Keywords are the words in a language that are used for some internal process or represent some predefined actions. char is a keyword that is used to declare a variable which store a character value from the range of +U0000 to U+FFFF. It is an alias of System.Char.
Syntax:
char variable_name = value;
char keyword occupies 2 bytes (16 bits) in the memory.
Example:
Input: S
Output: chr: S
Size of a char variable: 2
Input: G
Output: Type of chr: System.Char
chr: G
Size of a char variable: 2
Example 1:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
char chr = 'S' ;
Console.WriteLine( "chr: " + chr);
Console.WriteLine( "Size of a char variable: " + sizeof ( char ));
}
}
|
Output:
chr: S
Size of a char variable: 2
Example 2:
using System;
using System.Text;
namespace geeks {
class GFG {
static void Main( string [] args)
{
char chr = 'G' ;
Console.WriteLine( "Type of chr: " + chr.GetType());
Console.WriteLine( "chr: " + chr);
Console.WriteLine( "Size of a char variable: " + sizeof ( char ));
Console.ReadLine();
}
}
}
|
Output:
Type of chr: System.Char
chr: G
Size of a char variable: 2
Example 3:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
char chr = 'Geeks' ;
Console.WriteLine( "chr: " + chr);
Console.WriteLine( "Size of a char variable: " + sizeof ( char ));
}
}
|
Error:
Too many characters in character literal
Last Updated :
22 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...