我是靠谱客的博主 结实灯泡,最近开发中收集的这篇文章主要介绍C sharp(#)格式化输出对齐,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

不知道大家有没有过这样的疑问,当使用字符串输出计算的结果到屏幕上时,如果数据比较多,那么在屏幕上就会出现比较混乱的情况。因此这里来简单介绍一种输出方式能够输出整齐的结果。

using System;
using System.Collections.Generic;
using System.Text;

namespace MasterThesis
{
    class debug
    {
        static void Main(string[] args)
        {
            double[] array = new double[] {
                37.34630324062258,
                37.346157106190354,
                37.34571870289365,
                37.34498803073248,
                37.34396508970684,
                37.34264987981673,
                37.341042401062154,
                37.33914265344311,
                37.3369506369596,
                37.334466351611624,
                37.33168979739917,
                37.328620974322256,
                37.32525988238087,
                37.32160652157502,
                37.317660891904694,
                37.313422993369905,
                37.30889282597065,
                37.30407038970692,
                37.29895568457873,
                37.293548710586066,
                37.28784946772893,
                37.281857956007336,
                37.27557417542127,
                37.26899812597073,
                37.26212980765573,
                37.254969220476255,
                37.247516364432315,
                37.23977123952391,
                37.23173384575103,
                37.223404183113686,
                37.21478225161187,
                37.205868051245595,
                37.19666158201484,
                37.18716284391962,
                37.17737183695994,
                37.167288561135784,
                37.15691301644716,
                37.14624520289407,
                37.13528512047651,
                37.124032769194486,
                37.11248814904799,
                37.100651260037026,
                37.08852210216159,
                37.07610067542169,
                37.063386979817324,
                37.050381015348485,
                37.03708278201518,
                37.02349227981741,
                37.00960950875517,
                36.995434468828456,
                36.98096716003728,
                36.966207582381635,
                36.95115573586152,
                36.93581162047693,
                36.920175236227884,
                36.904246583114364,
                36.888025661136375,
                36.87151247029392,
                36.854707010587,
                36.837609282015606,
                36.82021928457974,
                36.802537018279416,
                36.78456248311462,
                36.76629567908535,
                36.747736606191616,
                36.728885264433416,
                36.709741653810745,
                36.69030577432361,
                36.670577625972,
                36.65055720875593,
                36.63024452267538,
                36.609639567730376,
                36.58874234392089,
                36.567552851246944,
                36.546071089708526,
                36.524297059305646,
                36.502230760038294,
                36.47987219190647,
                36.45722135491018,
                36.43427824904943,
                36.4110428743242,
                36.38751523073451,
                36.36369531828034,
                36.339583136961714,
                36.315178686778616,
                36.29048196773105,
                36.265492979819015,
                36.24021172304251,
                36.21463819740154,
                36.1887724028961,
                36.16261433952619,
                36.13616400729182,
                36.10942140619297,
                36.082386536229656,
                36.05505939740188,
                36.02743998970963,
                35.99952831315291,
                35.971324367731725,
                35.94282815344607,
                35.91403967029595
            };

            foreach (double element in array)
            {
                Console.Write("{0, -20}", element);
            }
            Console.WriteLine();
        }
    }
}

"{0, -20}"中的20表示表示20个占位符,-表示从左侧对齐,没有负号表示从右侧对齐。

最终的结果如下图所示:
在这里插入图片描述
我们可以看到输出结果实现了对齐。

码字不易,如果大家觉得有用,请高抬贵手给一个赞让我上推荐让更多的人看到吧~

最后

以上就是结实灯泡为你收集整理的C sharp(#)格式化输出对齐的全部内容,希望文章能够帮你解决C sharp(#)格式化输出对齐所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部