2017-2-17 C # Basic Learning (console program creation, output, input, definition variable, variable assignment, value overlay, value concatenation, value printing)

Source: Internet
Author: User
Tags ming

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.