📜  C#字符串Format()方法

📅  最后修改于: 2020-10-31 03:29:05             🧑  作者: Mango

C#字符串Format()

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[])

参量

first:这是一个字符串类型的参数。

第二:是对象类型参数。

返回

它返回一个格式化的字符串。

C#字符串Format()方法示例

    using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
                     
          string s1 = string.Format("{0:D}", DateTime.Now);
          Console.WriteLine(s1);
        }  
    }  

输出:

Saturday, December 17, 2016