C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# Format() 格式字符串

C# Format() 方法用于将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式。

签名

句法 (Syntax)

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

参数

首先:它是一个字符串类型的参数。

第二:它是对象类型参数。

返回

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


C# String Format() 方法示例

例子 (Example)

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 日星期六


  • 使用社交账号登录,本站支持
全部评论(0)