C# Convert ToChar(String, IFormatProvider)

Description

Convert ToChar(String, IFormatProvider) converts the first character of a specified string to a Unicode character, using specified culture-specific formatting information.

Syntax

Convert.ToChar(String, IFormatProvider) has the following syntax.


public static char ToChar(
  string value,
  IFormatProvider provider
)

Parameters

Convert.ToChar(String, IFormatProvider) has the following parameters.

  • value - A string of length 1 or null.
  • provider - An object that supplies culture-specific formatting information. This parameter is ignored.

Returns

Convert.ToChar(String, IFormatProvider) method returns A Unicode character that is equivalent to the first and only character in value.

Example

The following example converts a string representation of a Char value with the ToChar method, using an IFormatProvider object that displays the type of the format provider for which it is called.


using System;//w  ww  .ja va 2 s.  c  o  m
using System.Globalization;

public class DummyProvider : IFormatProvider
{
    public object GetFormat(Type argType)
    {
        string argStr = argType.ToString();
        if (argStr == "")
            argStr = "Empty";
        argStr = argStr.Substring(argStr.LastIndexOf('.') + 1);

        Console.Write("{0,-20}", argStr);
        return null;
    }
}

class ConvertNonNumericProviderDemo
{
    public static void Main()
    {
        DummyProvider provider = new DummyProvider();
    

        string Int32A = "-123456789";


        Console.WriteLine(Convert.ToChar(Int32A, provider));

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version