Convert.ToChar(String, IFormatProvider) Method in C#


The Convert.ToChar() method in C# is used to convert the first character of a specified string to a Unicode character, using specified culture-specific formatting information.

Syntax

Following is the syntax −

public static char ToChar (string val, IFormatProvider provider);

Above, the parameter value is a string of length 1 or null and the parameter provider is an object that supplies culture-specific formatting information. This parameter is ignored.

Example

Let us now see an example to implement the Convert.ToChar() method −

using System;
using System.Globalization;
public class Demo {
   public static void Main(){
      CultureInfo cultures = new CultureInfo("en-US");
      String val = "Z";
      Console.WriteLine("Converted char value...");
      char res = Convert.ToChar(val, cultures);
      Console.Write("{0}", res);
   }
}

Output

This will produce the following output −

Converted char value...
Z

Updated on: 05-Nov-2019

780 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements