C# | Char.ToString() Method

In C#, Char.ToString() is a System.Char struct method which is used to convert the value of this instance to its equivalent string representation. This method can be overloaded by passing different type of arguments to it.

  1. Char.ToString(IFormatProvider) Method
  2. Char.ToString(Char) Method
  3. Char.ToString() Method

Char.ToString(IFormatProvider) Method

This method is used to convert the value of the current instance to its equivalent string representation by using the specified culture-specific format information. The culture-specific format is a type of formatting, it is a process in which an instance value of class, structure, or enum is converted to the string representation and the result displayed to the user.



Syntax:

public string ToString(IFormatProvider provider);

Parameter:

provider: It is the required object which supplies culture-specific formatting information and it is reserved.

Return Type: It returns the string representation of the value of current instance which is specified by parameter provider. The return type of this method is System.String.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Char.ToString(IFormatProvider) Method
using System;
  
class GeeksforGeeks{
  
    // Main method
    public static void Main() {
  
        // converting into string
        Console.WriteLine(Char.ToString('G')); 
    }
}

chevron_right


Output:

G

Note: Here, the parameter provider, is ignored as it does not participate in this operation.

Char.ToString(Char) Method

This method is used to convert a specified Unicode character into a string representation.

Syntax:

public static string ToString(Char ch);

Parameter:


ch: It is the Unicode character which is to be converted.

Return Type: It returns a string representation of parameter ch. The return type of this method is System.String.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Char.ToString(Char) Method
using System;
  
class GeeksforGeeks{
  
    // Main method
    public static void Main() {
  
        // using ToString(Char) method
        // for converting char into string
        Console.WriteLine(Char.ToString('A'));
    }
}

chevron_right


Output:

A

Char.ToString() Method

This method is used to convert the value of this instance to its equivalent string representation.

Syntax:

public override string ToString();

Return Type: It returns a string representation of the value of this instance. The return type of this method is System.String.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// Char.ToString() Method
using System;
  
class GeeksforGeeks{
  
    // Main method
    public static void Main() {
  
        // declaration of data type
        char ch1 = 'P';
        string output;
  
        // convert into a string
        output = ch1.ToString();
        Console.WriteLine(output);
   
    }
}

chevron_right


Output:

P

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.tostring?view=netframework-4.7.2



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.