首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

writeline格式有关问题?多谢

2012-01-28 
writeline格式问题?谢谢!enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday }

writeline格式问题?谢谢!
enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
  enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
  [FlagsAttribute]
  enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

  public static void Main()
  {

  Type weekdays = typeof(Days);
  Type boiling = typeof(BoilingPoints);

  Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");

  foreach (string s in Enum.GetNames(weekdays))
  Console.WriteLine("{0,-11}= {1}", s, Enum.Format(weekdays, Enum.Parse(weekdays, s), "d"));

  Console.WriteLine();
  Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
  Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");

  foreach (string s in Enum.GetNames(boiling))
  Console.WriteLine("{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d"));

  Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
  Console.WriteLine();
  Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);其中的{0,-11}是什么意思?

[解决办法]
-11: left aligned within a space of 11 characters.


Console.WriteLine("{0:-11}", "Hello");
-11: |Hello______|

Console.WriteLine("{0:11}", "Hello");
 11: |______Hello|
[解决办法]
Correction to the previous post:

C# code
Console.WriteLine("{0,-11}", "Hello"); Console.WriteLine("{0,11}",  "Hello");
[解决办法]
Console.WriteLine("{0,-11}", "Hello"); ...从左面输出11个字符,不够的用_代替
Console.WriteLine("{0,11}", "Hello"); 从右面........

热点排行