📄 simple welcome program.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Simple Welcome Program</title>
</head>
<body background="../basic3.gif">
<p align="center"><font color="#FF0000" size="4"><b>Simple Welcome Program</b></font></p>
<table border="0" cellspacing="0" width="596">
<tr>
<td><font color="#008000">// Namespace Declaration<br>
using System;<br>
<br>
// Program start class<br>
class WelcomeCSS {<br>
<br>
// Main begins program
execution.<br>
public static void Main() {<br>
<br>
//
Write to console<br>
Console.WriteLine("Welcome to the C# Station Tutorial!"); <br>
<br>
}<br>
}</font></td>
</tr>
<tr>
<td>The program in Listing 1-1 has 4 primary elements, a namespace
declaration, a class, a "Main" method, and a program statement.</td>
</tr>
<tr>
<td>The namespace declaration indicates that you are referencing the
"System" namespace. Namespaces contain groups of code that
can be called upon by C# programs. With the "using
System;" declaration, you are telling your program that it can
reference the code in the "System" namespace without pre-pending
the word "System" to every reference. I'll discuss this in
more detail in a later lesson, dedicated specifically to namespaces.</td>
</tr>
<tr>
<td>The class declaration, "class WelcomeCSS", contains the data
and method definitions that your program uses to execute. It is one
of a few different types of elements your program can use to describe
objects, such as interfaces and structures, which will be discussed
in more detail in a later lesson. This particular class has no data,
but it does have one method. This method defines the behavior of
this class (or what it is capable of doing).</td>
</tr>
<tr>
<td>The one method within the WelcomeCSS class tells what this class will do
when executed. The method name, "Main", is reserved for
the starting point of a program. Before the word "Main" is
a "static" modifier. The "static" modifier
explains that this method works in this specific class only, rather than
an instance of the class. This is necessary, because when a program
begins, no object instances exist. Classes, objects, and instances
will be covered in more detail in a later lesson. Every method must have a
return type. In this case it is "void", which means that
"Main" does not return a value. Every method also has a
parameter list following it's name with zero or more parameters between
parenthesis. For simplicity, we did not add parameters to
"Main". Later in this lesson we'll show what type of
parameter the "Main" method can have.</td>
</tr>
<tr>
<td>The "Main" method specifies it's behavior with the "Console.WriteLine(...)"
statement. "Console" is a class in the "System"
namespace. "WriteLine(...)" is a method in the
"Console" class. We use the ".", dot, operator
to separate subordinate program elements. It should be interesting
to note that we could also write this statement as "System.Console.WriteLine(...)".
This follows the pattern "namespace.class.method" as a fully
qualified statement. Had we left out the "using System"
declaration at the top of the program, it would have been mandatory for us
to use the fully qualified form "System.Console.WriteLine(...)".
This statement is what causes the string, "Welcome to the C# Station
Tutorial!" to print on the console screen.</td>
</tr>
<tr>
<td>Observe that comments are marked with "//". These are
single line comments, meaning that they are valid until the end-of-line.
If you wish to span multiple lines with a comment, begin with
"/*" and end with "*/". Everything in between is
part of the comment. You may place a single line comment within a
multi-line comment. However, you can't put multi-line comments
within a multi-line comment. Comments are not considered when your
program is compiled. They are there to document what your program
does in plain english. </td>
</tr>
<tr>
<td>All statements end with a ";", semi-colon. Classes and
methods begin with "{", left curly brace, and end with a
"}", right curly brace. Any statements within and
including "{" and "}" define a block. Blocks
define scope (or lifetime and visibility) of program elements, which will
be discussed in a later lesson.</td>
</tr>
<tr>
<td>Many programs are written to accept command-line input. Collection
of command-line input occurs in the "Main" method. Listing
1-2 shows a program which accepts a name from the command line and writes
it to the console.</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -