C Sharp (C#) Char Data type


Char datatype is used when variables need to store characters. A character is assigned to a variable using single quotes. Char datatype allows 16 bits hence can accommodate Chinese, Japanese or any other language that uses Unicode characters. Though it belongs to integer category, numbers cannot be assigned to a character variable.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            char a = 'A';
            //assigning a number to char will take the ASCII value.
            char b = (char)104;
            Console.WriteLine("The variable a value is : {0}", a);
            Console.WriteLine("The variable b value is : {0}", b);
            Console.ReadLine();           
        }
    }
}

Output:

C Sharp Datatypes Home Page

No comments: