Char.TryParse() Method in C#



The Char.TryParse() method in C# is used to convert the value of the specified string to its equivalent Unicode character.

Syntax

public static bool TryParse (string str, out char res);

Let us now see an example to implement the Char.TryParse () method −

Example

using System;
public class Demo {
   public static void Main(){
      bool res;
      Char ch;
      res = Char.TryParse("10", out ch);
      Console.WriteLine(res);
      Console.WriteLine(ch.ToString());
   }
}

Output

This will produce the following output −

False

Let us now see another example −

Example

using System;
public class Demo {
   public static void Main(){
      bool res;
      Char ch;
      res = Char.TryParse("P", out ch);
      Console.WriteLine(res);
      Console.WriteLine(ch.ToString());
   }
}

Output

This will produce the following output −

True
P
Updated on: 2019-11-04T10:59:21+05:30

455 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements