C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
Data Literals - Example
This section provides a tutorial example on how to enter data literals into C# programs. 5 types of data literals used in C#: Boolean, Integer, Real, Character and String.
Now let's apply what we have learned so far, and write the following experimental program with literals.cs as the file name:
// Literals.cs
// Copyright (c) 2006 HerongYang.com. All Rights Reserved.
class Literals {
public static void Main() {
System.Console.WriteLine(
"Boolean literals: {0} and {1}.", true, false);
System.Console.WriteLine(
"Integer literals: {0}, {1}, {2}, {3}.", 0, 555, -777, 911);
System.Console.WriteLine(
"Real literals: {0}, {1}, {2}, {3}.", 0.0, 555.0, -777.0,
3.14159);
System.Console.WriteLine(
"Character literals: {0}, {1}, {2}, {3}.", 'a', 'A', '0',
'9');
System.Console.WriteLine(
"Character literals: {0}, {1}, {2}, {3}, {4}.", '\t', '\r',
'\n', '\"', '\\');
System.Console.WriteLine(
"String literals: {0}, {1}, {2}.", "911", "Hello world!",
"Joe said \"Hello\" to me.");
}
}
After compiling and executing the program, we will get the following output:
Boolean literals: True and False. Integer literals: 0, 555, -777, 911. Real literals: 0, 555, -777, 3.14159. Character literals: a, A, 0, 9. , aracter literals: , , ", \. String literals: 911, Hello world!, Joe said "Hello" to me..
There are a couple of interesting things to be noted here:
Table of Contents
Variables and Assignment Statements
Variables and Assignments - Example
Arithmetic Operations - Example
Logical Expressions and Conditional Statements
Visual C# 2010 Express Edition
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation