1.
usingSystem;usingSystem.Collections.Generic;usingsystem.ling;usingSystem.Text;usingSystem.Threading.Tasks;//namespaces, supporting class library callsnamespaceHelloWorld//Project Name{ classProgram//This is a class { Static voidMain (string[] args)//method (Main method)/main function { //program run start placeConsole.WriteLine ("Hello World");//Output DisplayConsole.readkey ();//Pause Program } }}
2.
usingSystem;usingSystem.Collections.Generic;usingsystem.ling;usingSystem.Text;usingSystem.Threading.Tasks;//namespaces, supporting class library callsnamespaceHelloWorld//Project Name{ classProgram//This is a class { Static voidMain (string[] args)//method (Main method)/main function { intnum; Num=Ten;//define an Integer variable DoubleD//decimal type, double contains an int floatf =3.14f;//uniity using floatD =3.14; stringstr; STR="Huang";//double quotes required CharC//Single -characterc ='a';/ar assignment with single quotation markBOOLb//Boolean type, judging right and wrongb =true; b=false; Console.WriteLine (num); } }}
3. Name of the variable:
Naming rules:
1. Must start with "letter" _ or @, do not start with a number
2 can be followed by any "letter", number, underline.
Attention:
1. The variable name you are starting with is not duplicated with keywords in the C # system.
2. In C #, casing is sensitive.
3. Duplicate definitions are not allowed for the same variable name (first thought, not rigorous)
Variable names make sense when defining variables
C # variable naming coding specification--camel nomenclature:
The first letter is lowercase and the first letter of the remaining words is capitalized.
Pascal naming conventions: Capitalize each word in the first letter
If you use abbreviations for English words, capitalize them all!
Strings that are concatenated with other types become strings.
Practice
1.
usingSystem;namespace_001lianxi{classProgram {Static voidMain (string[] args) { stringName ="Kaka West"; stringPlace ="Fire Shadow Village"; intAge = -; stringPostbox ="[email protected]"; DoubleWage = -; //Console.WriteLine ("I call" + name+ ", I live in" + place+ ", I this year" + age+ ", my mailbox is" + postbox + ", my salary is" + wage);Console.WriteLine ("My name is {0}, this year {1} years old, home address is {2}, my mailbox is {3}, my salary is {4}", name, age, place, postbox, wage); } }}
2.
Exchange variable values:
using System; namespace _005{ class program { static void Main (string [] args) { int a = 10 ; int b = 5 ; A = b- A; b = b- A; A = a + b; Console.WriteLine (a); Console.WriteLine (b); } }}
3.
usingSystem;namespace_007{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter your name"); stringName = Console.ReadLine ();//input used to receive the userConsole.WriteLine ("Please enter your age"); stringAge =Console.ReadLine (); Console.WriteLine ("Please enter gender"); stringGender =Console.ReadLine (); Console.WriteLine ("hello: {0} sir, your age is {1}, or a handsome and pressing {2} born", name, age, Gender); } }}
4.
C # Learning Primer First article