文档介绍:C# Pocket Reference
C# is a general-purpose, type-safe, object-oriented programming language. The goal of
the language is programmer productivity. To this end, the language balances simplicity,
expressiveness, and performance. The C# language is platform-neutral, but it was written
to work well with the Microsoft .NET Framework. C# targets .NET Framework .
The programs and code snippets in this book mirror those in Chapters 2-4 of
C# in a Nutshell and are all available as interactive samples in LINQPad.
Working through these samples in conjunction with the book accelerates
learning in that you can edit the samples and instantly see the results without
needing to set up projects and solutions in Visual Studio.
To download the samples, click the Samples tab in LINQPad and click
“Download more samples”. LINQPad is free—go to .
A First C# Program
Here is a program that multiplies 12 by 30, and prints the result, 360, to the screen. The
double forward slash indicates that the remainder of a line is ment.
using System; // Importing namespace
class Test // Class declaration
{
static void Main() // Method declaration
{
int x = 12 * 30; // Statement 1
(x); // Statement 2
} // End of method
} // End of class
At the heart of this program lies two statements. Statements in C# execute sequentially
and are terminated by a semicolon. The first putes the expression 12 * 30
and stores the result in a local variable, named x, which is an integer type. The second
statement calls the Console class’s WriteLine method, to print the variable x to a
text window on the screen.
A method performs an action in a series of statements, called a statement block—a pair of
braces containing zero or more statements. We defined a single method named Main.
Writing higher-level functions that call upon lower-level functions simplifies a program.
We can refactor our program with a reusable