c# - How to parse a string into char

String to char
.net Char.Parse() method allow us to convert the value of the specified string to its equivalent Unicode character. this method exists in System namespace. the Char.Parse() method require to pass a parameter named 's'. the 's' parameter value type is System.String. this string contains a Unicode character or null.

this Char.Parse() method return value type is System.Char. the return value is a Unicode character that is equivalent to the single character of parameter 's'. finally we convert the string object to a char object.

the following .net c# example code demonstrate us how can we convert or parse a string object to char in an asp.net application.

<%@ Page Language="C#" AutoEventWireup="true"%>  
<!DOCTYPE html>    
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
        //this section create a string variable.  
        string stringOfChar = "A";  
        Label1.Text = "string of single character..................<br />";
        Label1.Text += stringOfChar;

        //this line convert/parse/transform string to char.
        //for this conversion you need a 1 character lenght string.
        char c = char.Parse(stringOfChar);
        Label1.Text += "<br /><br />converted char from string.........<br />";
        Label1.Text += c;

        Label1.Text += "<br /><br />type of the current instance .........<br />";
        Label1.Text += c.GetType();

        Label1.Text += "<br /><br />type of the current instance (string).........<br />";
        Label1.Text += stringOfChar.GetType();
<html xmlns="http://www.w3.org/1999/xhtml">    
<head id="Head1" runat="server">    
    <title>c# example - string to char</title>    
    <form id="form1" runat="server">    
        <h2 style="color:MidnightBlue; font-style:italic;">    
            c# example - string to char
        <hr width="550" align="left" color="Gainsboro" />    
        <br /><br />  
            Text="string to char"    
More c# examples