using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;namespace DirecotyLister1
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(".");
foreach (FileInfo f in dir.GetFiles ("*.cs"))
{
string name = f.FullName;
long size = f.Length;
DateTime time = f.CreationTime;
Console.WriteLine("{0,-12:N0} {1,-20:g} {2}", size,time, name); //"-12:N0","-20:g"是什么意思,能否详细讲解一下
Console.WriteLine("{0} {1} {2}", size, time, name);
Console.WriteLine();
}
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;namespace DirecotyLister1
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(".");
foreach (FileInfo f in dir.GetFiles ("*.cs"))
{
string name = f.FullName;
long size = f.Length;
DateTime time = f.CreationTime;
Console.WriteLine("{0,-12:N0} {1,-20:g} {2}", size,time, name); //"-12:N0","-20:g"是什么意思,能否详细讲解一下
Console.WriteLine("{0} {1} {2}", size, time, name);
Console.WriteLine();
}
Console.Read();
}
}
}
表示短日期 (d) 和短时间 (t) 模式的组合,由空格分隔
12和20表示最小长度。-号,表示靠左对齐。NO好像还真没见过。
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal sortable: . . . Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
("{0,-12:N0} {1,-20:g}中间的数字表示宽度和对齐方式,当数据长度小于该数字绝对值指定的宽度时,正为右对齐,负为左对齐,再后面的G表示数据格式