C # read as Sharp
. CS is the file suffix name of the source code that is written in the C # language.
Console application creation steps: Open vs, click File, select "New"-"Project", select Template Visual C #, framework. NET Framework, Application console control program. Select a location to save and name the file.
Writing code in the main function
Console WriteLine ("content to output"); Used to output content
Console ReadLine (); Wait for user input, press ENTER to end, prevent program Flash.
usingSystem.Text;namespacePractice 1{classProgram {Static voidMain (string[] args) { //Input ContentConsole.WriteLine ("please click on the xx button in the upper right corner"); Console.ReadLine (); Console.WriteLine ("Why don't you point it out?"); Console.WriteLine ("Good , obedient."); Console.ReadLine (); Console.WriteLine ("I'll turn it off by myself ."); Console.ReadLine (); Console.WriteLine ("well, bye ."); //to prevent flash back, press ENTER to end. Console.ReadLine (); } }}
--------------------------------------------------------------
Variable
Content printing:
Console.writelline ("content"); Console.writel ("content");//No line will be automatically wrapped
Variable printing:
Console.writelline (variable name); Console.writel (variable name);
To receive user input:
Console.ReadLine (); -Returns a string (string) type of value
String strings
Defines a variable string A;
Variable assignment value a= "value";
Combine string a= "value", and two string type "+" to stitch the two strings.
int integer type variable.
Define the shaping variable int A;
Shaping variable assignment a=1;
The shaping variable can be "+-*/" and the result is the result of a mathematical operation.
How do I convert a string type to an integer type?
String a= "10";
int B=int.parse (a);
A variable cannot have a duplicate name, regardless of the type of variable.
Variables must first be defined and reused.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespace_0217 Job7 {8 class Program9 {Ten Static voidMain (string[] args) One { A //user Input -Console.Write ("Please enter your name:"); - stringA =console.readline (); the -Console.Write ("Please enter your gender:"); - stringb =console.readline (); - +Console.Write ("Please enter your age:"); - stringc =console.readline (); + AConsole.Write ("Please enter your height:"); at stringD =console.readline (); - intf =int. Parse (d); - -Console.Write ("Please enter your weight:"); - stringE =console.readline (); - intg =int. Parse (e); in -Console.WriteLine ("---------------------Gorgeous split-line---------------------"); to +Console.Write (A +"Hi there! "); -Console.Write ("your gender is ""+b); theConsole.Write ("", your age is""+c); *Console.Write (", your height is ""+d); $Console.Write (""and your weight is""+e);Panax NotoginsengConsole.WriteLine ("". "); - the inth = f +G; + AConsole.Write ("your height and weight and is ""+h); theConsole.WriteLine ("". "); //prevent flash back - console.readline (); Wu } - } About}
2017-02-17c# Basics-Define variables, input and output