First part C # language overview
Chapter One. slightly
Chapter two. slightly
third chapter. Write the first application
3.1welcome program
1. Let the user enter your own name from the keyboard, then print a welcome information on the screen screen.
Using system;
Class Welcome
{
Static void
Main
()
{
Console.writeline ("please write your name:");
Console.readline ();
Console.writeline ("Welcome to C # World!");
}
}
2. Typical C # source file extensions are ".cs".
3.2 Code Analysis
1. C # language case sensitive, pay attention to the place where you write.
2.1: Name Space: USING SYSTEM represents import namespace, like #include in C language.
2.2: If you do not import namespace, the program can be implemented, the code is changed to:
Class Welcome
{
Static void
Main
()
{
System.Console.writeline ("please write your name:");
System.console.readline ();
System.Console.writeline ("Welcome to C # World!");
}
}
3. The composite name in C # will be used ".".
4. System is one of the most basic namespaces provided by the .NET platform framework.
5.1 Class: Class Welcome is the statement of the class. What we have to do is done by it. Like C, C , {} must be used.
5.2: Method of class: static void main () is a method in class Welcome.
5.3: There is only one main () method in C #, and must be included in a class, and the execution of the program starts from main ().
6. The input and output of the program is done by console.
Console method:
Readline: Indicates the acceptance device input. (Plus a reply button is equivalent to execution)
WriteLine: Used to output on the output device. (Plus a reply button is equivalent to execution)
Read: indicates the acceptance device input.
WRITE: It is used to output on the output device.
7. Example of expansion:
Using system;
Class Welcome
{
Class void
Main
()
{
Console.writeline ("Pease Enter Your Name:");
String name = console.readline ();
Console.writeline ("Welcome to you, {0}!", Name);
}
}
8. Console.writeline ("Welcome to you, {0}!", Name represents formatting the string output on the screen. It indicates that the second parameter of the method is used to replace the corresponding position accordingly. The parameters formatted to the string can be a string or a character, or an integer. This method can be used to format three variables.
9. Run the program
10. C # annotation: single line comments // and multi-line comments / ** /.
11. Section:
● How to interact with the user in the application.
● How to perform an input and output and format the string through the method provided by System predefined class console. ● How to compile C # source files.
● How to add a comment to your code.
12. Review questions:
● How does the C # program typically start executing?
● What input and output will be provided to us with a CONSOLE class?
● Explain how to use a compiler to generate different types of output files.
● Do you have to comment on the source file? why?
● Tell you to pay attention to what questions should be paid to the C # code.
************************** Chapter 3 * ****************** ************