加拿大华人论坛 美国华人新闻C# 中字符串的格式化
在加拿大
格式化日期输出形式取决于用户计算机的文化设置。using System;using System.Globalization;public class MainClass{ public static void Main(string[] args) { DateTime dt = DateTime.Now; String[] format = {"d","D","f","F","g","G","m","r","s","t", "T","u", "U","y","dddd, MMMM dd yyyy","ddd, MMM d "'"yy","dddd, MMMM dd","M/yy","dd-MM-yy",}; String date; for (int i = 0; i < format.Length; i++) { date = dt.ToString(format[i], DateTimeFormatInfo.InvariantInfo); Console.WriteLine(String.Concat(format[i], " :" , date)); } }}d :07/11/2004 <=======输出D :Sunday, 11 July 2004f :Sunday, 11 July 2004 10:52F :Sunday, 11 July 2004 10:52:36g :07/11/2004 10:52G :07/11/2004 10:52:36m :July 11r :Sun, 11 Jul 2004 10:52:36 GMTs :2004-07-11T10:52:36t :10:52T :10:52:36u :2004-07-11 10:52:36ZU :Sunday, 11 July 2004 02:52:36y :2004 Julydddd, MMMM dd yyyy :Sunday, July 11 2004ddd, MMM d "'"yy :Sun, Jul 11 '04dddd, MMMM dd :Sunday, July 11M/yy :7/04dd-MM-yy :11-07-043.3 格式化枚举enum classmen{ ynn=1, yly=2, css=3, C++=4}获取枚举字符串信息如下:classmen myclassmen=classmen.yly;Console.WriteLine(myclassmen.ToString( )); //displays ylyConsole.WriteLine(myclassmen.ToString("d")); //displays 2从系统枚举中获取文本人信息如下:DayOfWeek day=DayOfWeek.Friday;//displays "Day is Friday"Console.WriteLine(String.Format("Day is {0:G}",day));格式化字符串“ G ”把枚举显示为一个字符串。
·中文新闻 UberEats 员工通过他有史以来最简单的送货服务赚取了 6 美元
·中文新闻 《我是名人》明星卡勒姆·霍尔 (Callum Hole) 为澳大利亚海岸带来