C# | Convert.ToString(String, IFormatProvider) Method - GeeksforGeeks

02 Sep, 2021
This method is used to returns the specified string instance and no actual conversion is performed.Syntax:
public static string ToString (String, IFormatProvider);
Parameters:  
value: It is the string to return.
provider: It is an object that supplies culture-specific formatting information. This parameter is ignored.
Return Value: This method returns value is returned unchanged.Below programs illustrate the use of Convert.ToString(String, IFormatProvider) Method:Example 1: 
csharp
// C# program to demonstrate the// Convert.ToString() Methodusing System;using System.Globalization; class GFG {     // Main Method    public static void Main()    {        try {             // creating object of CultureInfo            CultureInfo cultures =              new CultureInfo("en-US");             // declaring and initializing String array            string[] values = {"amar", "akbar",                                    "anthony"};             // calling get() Method            Console.Write("Converted string value"                  + " from a specified string: ");             for (int j = 0; j < values.Length; j++)            {                get(values[j], cultures);            }        }         catch (FormatException e)        {            Console.WriteLine("\n");            Console.Write("Exception Thrown: ");            Console.Write("{0}", e.GetType(), e.Message);        }         catch (OverflowException e)        {            Console.WriteLine("\n");            Console.Write("Exception Thrown: ");            Console.Write("{0}", e.GetType(), e.Message);        }    }     // Defining get() method    public static void get(string s,               CultureInfo cultures)    {         // converting string to specified string        string val = Convert.ToString(s, cultures);         // display the converted string value        Console.Write(" {0} ", val);    }}
Converted string value from a specified string:  amar  akbar  anthony
 
Example 2:
csharp
// C# program to demonstrate the// Convert.ToString() Methodusing System;using System.Globalization; class GFG {     // Main Method    public static void Main()    {        // creating object of CultureInfo        CultureInfo cultures =          new CultureInfo("en-US");         // declaring and initializing a String array        string value = "The Accidental Prime Minister";         // calling get() Method        Console.Write("Converted String: ");         // converting string to specified string        string val = Convert.ToString(value, cultures);         // display the converted string value        Console.Write("{0}", val);    }}
Converted String: The Accidental Prime Minister
 
Reference: 
https://docs.microsoft.com/en-us/dotnet/api/system.convert.tostring?view=netframework-4.7.2#System_Convert_ToString_System_String_System_IFormatProvider_ 
sweetyty
CSharp Convert Class
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
C# | Method Overriding
C# | Constructors
Difference between Ref and Out keywords in C#
C# | Class and Object
Introduction to .NET Framework
C# | Delegates
Extension Method in C#
C# | Abstract Classes
C# | Data Types