ASP.NET Basics (part 2): Not My Type - Strange Characters
(Page 4 of 10 )
A close relative of the "string" data type is the "char" data type. As you might have guessed, this data type is used to store a single character (unlike the "string" type, which is used to store a sequence of characters). Take a look at the next example, which demonstrates how character variables work.
<script language="C#" runat="server">
void Page_Load()
{
char saviour; // define a character variable
saviour = 'Q'; // assign a value
answer.Text = "James Bond's favourite mad scientist is...<b>" + saviour + "</b>";
}
</script>
<html>
<head><title>James Bond Trivia</title></head>
<body>
<asp:label id="answer" runat="server" /></b>
</body>
</html>
Here's the output.

No rocket science here: the "char" keyword is used to define a character variable,
<%
char saviour; // define a character variable
%>
and the assignment operator is used to assign it a value.
<%
saviour = 'Q'; // assign a value
%>
If you have a sharp eye, you will notice that the initialization of a character variable is slightly different from that of a string variable - when initializing a character variable, you must use single quotes instead of double quotes, or else the program will barf and say the following:

Next: Playing The Numbers >>
More ASP.NET Code Articles
More By Harish Kamath (c) Melonfire