如何存在以下输出 [英] How do the following output Exists

查看:64
本文介绍了如何存在以下输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下网站中阅读字符串构建器的类详细信息时



http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(v=vs.110).aspx [ ^ ]



While reading class details of String builder in the following site

http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(v=vs.110).aspx[^]

using System;
using System.Reflection;
using System.Text;

public class Example
{
   public static void Main()
   {
      StringBuilder sb = new StringBuilder();
      ShowSBInfo(sb);
      sb.Append("This is a sentence.");
      ShowSBInfo(sb);
      for (int ctr = 0; ctr <= 10; ctr++) {
         sb.Append("This is an additional sentence.");
         ShowSBInfo(sb);
      }   
   }

   private static void ShowSBInfo(StringBuilder sb)
   {
      foreach (var prop in sb.GetType().GetProperties()) {
         if (prop.GetIndexParameters().Length == 0)
            Console.Write("{0}: {1:N0}    ", prop.Name, prop.GetValue(sb));
      }
      Console.WriteLine();
   }
}
// The example displays the following output: 
//    Capacity: 16    MaxCapacity: 2,147,483,647    Length: 0 
//    Capacity: 32    MaxCapacity: 2,147,483,647    Length: 19 
//    Capacity: 64    MaxCapacity: 2,147,483,647    Length: 50 
//    Capacity: 128    MaxCapacity: 2,147,483,647    Length: 81 
//    Capacity: 128    MaxCapacity: 2,147,483,647    Length: 112 
//    Capacity: 256    MaxCapacity: 2,147,483,647    Length: 143 
//    Capacity: 256    MaxCapacity: 2,147,483,647    Length: 174 
//    Capacity: 256    MaxCapacity: 2,147,483,647    Length: 205 
//    Capacity: 256    MaxCapacity: 2,147,483,647    Length: 236 
//    Capacity: 512    MaxCapacity: 2,147,483,647    Length: 267 
//    Capacity: 512    MaxCapacity: 2,147,483,647    Length: 298 
//    Capacity: 512    MaxCapacity: 2,147,483,647    Length: 329 
//    Capacity: 512    MaxCapacity: 2,147,483,647    Length: 360





如何进行上述输出。
如果是这样,那么下面显示的代码类似于





How the above output is possible.
If so then what the code shown below resembles

Console.Write("{0}: {1:N0}    ", prop.Name, prop.GetValue(sb));





以上代码中{1:N0}的用途





任何人都可以解释这个



what is the use of {1:N0} in the above code


Can anyone explain this

推荐答案

你好Kumar,



以上输出是可能。



使用 {1:N0} 在给定的行中是



它会将第一个参数值打印为千位分隔值。



N0是一种字符串格式。

如果你没有使用N0那么属性的值将是普通数字。



通过使用N0,它显示为逗号分隔的数值。





希望这对你有帮助......



Th anks,

Nani。
Hi Kumar,

Above output is possible.

the use of {1:N0} in the given line is

It will print the first argument value as a thousand separated value.

N0 is one type of the string formats.
If you have not used N0 then the the values of the properties will be as plain number.

By using N0 it is appearing as a comma separated numeric value.


Hope this helps you...

Thanks,
Nani.


这篇关于如何存在以下输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆