C# Format() 方法用于将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式。
public static string Format (String first, Object second) public static string Format(IFormatProvider, String, Object) public static string Format(IFormatProvider, String, Object, Object) public static string Format(IFormatProvider, String, Object, Object, Object) public static string Format(IFormatProvider, String, Object[]) public static string Format(String, Object, Object) public static string Format(String, Object, Object, Object) public static string Format(String, params Object[])
首先:它是一个字符串类型的参数。
第二:它是对象类型参数。
它返回一个格式化的字符串。
using System; public class StringExample { public static void Main(string[] args) { string s1 = string.Format("{0:D}", DateTime.Now); Console.WriteLine(s1); } }
输出:
2016 年 12 月 17 日星期六