| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 400 人关注过本帖
标题:问一个函数的作用
只看楼主 加入收藏
nba568
Rank: 2
等 级:论坛游民
帖 子:8
专家分:12
注 册:2011-4-13
收藏
 问题点数:0 回复次数:1 
问一个函数的作用
小弟刚学C#,想问一下string.Format()函数的作用,最好能举个例子,感谢各位大虾~
搜索更多相关主题的帖子: 函数 最好 
2011-05-09 21:04
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
From MSDN:
程序代码:
// This code example demonstrates the String.Format() method.
// Formatting for this example uses the "en-US" culture.

using System;
using System.Globalization;

class Sample
{
    enum Color {Yellow = 1, Blue, Green};
    static DateTime thisDate = DateTime.Now;

    public static void Main()
    {
// Store the output of the String.Format method in a string.
    string s = "";

    Console.Clear();

// Format a negative integer or floating-point number in various ways.
    Console.WriteLine("Standard Numeric Format Specifiers");
    s = String.Format(CultureInfo.InvariantCulture,
        "(C) Currency: . . . . . . . . {0:C}\n" +
        "(D) Decimal:. . . . . . . . . {0:D}\n" +
        "(E) Scientific: . . . . . . . {1:E}\n" +
        "(F) Fixed point:. . . . . . . {1:F}\n" +
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(N) Number: . . . . . . . . . {0:N}\n" +
        "(P) Percent:. . . . . . . . . {1:P}\n" +
        "(R) Round-trip: . . . . . . . {1:R}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        -123, -123.45f);
    Console.WriteLine(s);

// Format the current date in various ways.
    Console.WriteLine("Standard DateTime Format Specifiers");
    s = String.Format(CultureInfo.InvariantCulture.DateTimeFormat,
        "(d) Short date: . . . . . . . {0:d}\n" +
        "(D) Long date:. . . . . . . . {0:D}\n" +
        "(t) Short time: . . . . . . . {0:t}\n" +
        "(T) Long time:. . . . . . . . {0:T}\n" +
        "(f) Full date/short time: . . {0:f}\n" +
        "(F) Full date/long time:. . . {0:F}\n" +
        "(g) General date/short time:. {0:g}\n" +
        "(G) General date/long time: . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(M) Month:. . . . . . . . . . {0:M}\n" +
        "(R) RFC1123:. . . . . . . . . {0:R}\n" +
        "(s) Sortable: . . . . . . . . {0:s}\n" +
        "(u) Universal sortable: . . . {0:u} (invariant)\n" +
        "(U) Universal sortable: . . . {0:U}\n" +
        "(Y) Year: . . . . . . . . . . {0:Y}\n",
        thisDate);
    Console.WriteLine(s);

// Format a Color enumeration value in various ways.
    Console.WriteLine("Standard Enumeration Format Specifiers");
    s = String.Format(CultureInfo.InvariantCulture,
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
        "(D) Decimal number: . . . . . {0:D}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        Color.Green);      
    Console.WriteLine(s);
    }
}
/*
This example displays the following output to the console:

Standard Numeric Format Specifiers
(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:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 07/09/2007
(D) Long date:. . . . . . . . Monday, 09 July 2007
(t) Short time: . . . . . . . 13:48
(T) Long time:. . . . . . . . 13:48:05
(f) Full date/short time: . . Monday, 09 July 2007 13:48
(F) Full date/long time:. . . Monday, 09 July 2007 13:48:05
(g) General date/short time:. 07/09/2007 13:48
(G) General date/long time: . 07/09/2007 13:48:05
    (default):. . . . . . . . 07/09/2007 13:48:05 (default = 'G')
(M) Month:. . . . . . . . . . July 09
(R) RFC1123:. . . . . . . . . Mon, 09 Jul 2007 13:48:05 GMT
(s) Sortable: . . . . . . . . 2007-07-09T13:48:05
(u) Universal sortable: . . . 2007-07-09 13:48:05Z (invariant)
(U) Universal sortable: . . . Monday, 09 July 2007 20:48:05
(Y) Year: . . . . . . . . . . 2007 July

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
    (default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/




[ 本帖最后由 zhoufeng1988 于 2011-5-10 09:39 编辑 ]
2011-05-10 09:37
快速回复:问一个函数的作用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017064 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved