1 Creating a console program
> New Project, select C #, frame Select 4.0, select Control application program, select File save location to modify name.
2 C # output and input
> Writing code in the main function
> can insert Console.ReadLine () at the time of writing to prevent program Flash
>
Console.Write (" instance statement "); // No Line break output Console.WriteLine (" sample statement "); // line break output Console.ReadLine (); // wait for user input to prevent flash back
The results are as follows
3 Defining variable Assignments
string a =" yaowei"; // define variables and assign values Console.WriteLine (a); // Output console.readline (); string b = Console.ReadLine (); // define variable b waits for user input information Console.WriteLine (b); // Output user input information Console.ReadLine ();
The results are as follows,
4-Value stitching defines shaping variables to transform strings into integers
stringx ="Yao"; stringy ="Wei"; stringz = x + y;//Value StitchingConsole.WriteLine (z);// intK =1; intL =2; intm = k +l; Console.WriteLine (m);//output is 3
> Integer can perform "+-*/" operations, resulting in mathematical operations
Exercise "Please enter your name:" A cursor appears on the same line, waiting for the user to enter
"Please enter your gender:" Cursor, waiting for user input
"Please enter your age:" Ibid.
"Please enter your height:" Ibid.
"Please enter your weight:" Ibid.
"--------------------Gorgeous split-line-----------------------"
XXX Hello! Your gender is "male", your age is "18", your height is "180", your weight is "180".
Console.Write ("Please enter your name:");//No line break output stringxingming = Console.ReadLine ();//wait for user inputConsole.Write ("Please enter your gender:"); stringXingbie =Console.ReadLine (); Console.Write ("Please enter your age:"); stringnianling=Console.ReadLine (); Console.Write ("Please enter your height:"); stringshengao=Console.ReadLine (); Console.Write ("Please enter your weight:"); stringTizhong =Console.ReadLine (); Console.WriteLine ("----------------------------Gorgeous split-line------------------------------"); //define variables and assign values stringA ="Hello! ", B ="your gender is "", C ="", your age is"", d ="", your height is"", E =""and your weight is"", F ="". "; stringEnd = xingming + A + B + Xingbie + C + nianling + D + Shengao + E + Shengao + F;//Merge all statements with user inputConsole.WriteLine (end);//Print the final result intx =int. Parse (Shengao); inty =int. Parse (Tizhong); intz = x +y; stringL ="your height and weight are "", k ="". "; stringhe = L + z +K; Console.WriteLine (He); Console.ReadLine ();
The actual results are as follows
Personal understanding in practice do not blindly define variables first clear ideas
Notice the punctuation in the actual application
、
His exercises fell Xia and solitary Mo Fei Qi, the eyes of a total of sky. (In the blanks)
This poem is from the vine Wang GE sequence.
Congratulations on your answer! (second line)
Fall Xia and solitary Mo Fei qi,? The eyes are all over the sky. This verse is from? Rattan Wang GE sequence.
-----------Cut------------
How many words are there in two verses?
How many words is the name of the poem?
Poems and poems are 18 words in name.
》》
Code
Console.Write ("Fall Xia and solitary Mo Fei Qi,");//First line stringShi = Console.ReadLine ();//wait for user inputConsole.Write ("This poem comes from"); stringMing =Console.ReadLine (); Console.WriteLine ("congratulations on your answer! "); stringA ="Fall Xia and solitary Mo Fei Qi,", B =". The poem comes from the", C ="". ";//Defining Variables stringend = a + Shi + B + ming + C;//Final ResultConsole.WriteLine (end); Console.WriteLine ("--------------Cut--------------------"); Console.Write ("How many words are there in two verses?"); stringx =Console.ReadLine (); Console.Write ("How many words is the name of the poem? "); stringy =Console.ReadLine (); intK =int. Parse (x);//Transform shaping variables intL =int. Parse (y); intz = k +l; stringU ="Poetry and poetry in the name of the total", i ="a word. "; stringp = U + z +i; Console.WriteLine (P); Console.ReadLine ();
The actual results are as follows
2017-2-17 C # Basic Learning (console program creation, output, input, definition variable, variable assignment, value overlay, value concatenation, value printing)