Boolean.ToString(IFormatProvider)方法用於將當前實例的值轉換為其等效的字符串表示形式,該表示形式可以是“True”或“False”
用法:
public string ToString (IFormatProvider provider);
參數:此方法采用IFormatProvider類型的對象,該對象保留。
返回值:如果此實例的值為true,則此方法返回TrueString;如果此實例的值為false,則返回FalseString。
例:
// C# program to demonstrate
// Boolean.ToString(IFormatProvider)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing
// Boolean value
bool s1 = true;
// creating and initializing
// the object of CultureInfo
CultureInfo provider = new CultureInfo("en-us");
// Using the method
string str = s1.ToString(provider);
// Display the value
Console.WriteLine("The Value is {0} and provider is {1}",
str, provider.Name);
}
}
輸出:
The Value is True and provider is en-US
注意:提供者參數是保留的,因為它在執行此方法時不會有任何貢獻。這意味著,與大多數帶有提供程序參數的方法不同,此方法不反映特定於區域性的設置。
參考:
相關用法
- C# DateTimeOffset.Add()用法及代碼示例
- C# String.Contains()用法及代碼示例
- C# Math.Sin()用法及代碼示例
- C# Math.Cos()用法及代碼示例
- C# Dictionary.Add()用法及代碼示例
- C# Math.Tan()用法及代碼示例
- C# Math.Abs()方法用法及代碼示例
- C# Math.Exp()用法及代碼示例
- C# Math.Abs()函數用法及代碼示例
注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 Boolean.ToString(IFormatProvider) Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。