The main learning contents are:
Console program creation, output, input, definition variables, variable assignment, value overlay, value stitching, value printing
Two types of data, integer type conversions
The programming language file name suffix is. cs
Steps to create a program project:
FILE--New--Project--visual C # ——. Net Framework 4--Console Application--setting name and location--OK
Solution Explorer can set up a project to write or start
Writing code in the main function
Print content:
Output to the outside of the content
Console.WriteLine ("Content of output"); Line break
Console.Write ("Content of output"); No Line break
To receive user input:
Wait for user input, press ENTER to end, prevent program Flash back
Console.ReadLine (); -Returns a string (string) type of value
( note that when writing the code, the first letter is capitalized, the punctuation is not omitted and the English format )
Tools--Options--text editor--c#--display--line number view number of lines of code
Tools--Options--environment--general--color theme can set program background
Tools--Options--environment--fonts and colors--consolas Set write-code-specific fonts
Define variables: ( must start letter, do not have a special symbol, try not to use Chinese, you must define the post-assignment, you can not repeat the definition of variables, one-time definition of multiple variables, separated by commas )
String A; or string a = "value"
Variable assignment: (the variable must be on the left side)
A = "value";
Print variables:
Console.WriteLine (variable name);
Console.Write (variable name);
Two string type "+" operation, the result is: stitching
Two string types cannot be subtracted
1 Console.WriteLine ("Please enter your name"); 2 string name =console.readline (); 3 string nihao="Hello,"; 4 string end =nihao +name; 5 Console.WriteLine (end); 6 console.readline ();
To define an integer variable:
int A; or int a = number
Integer variable assignment:
A = number;
An integer variable can perform a "+-*/" operation, resulting in a mathematical operation
How do I convert a string type to an integral type?
String a = "number";
int b = Int. Parse (a);
1 string a =console.readline (); 2 int b =int. Parse (a);3Console.WriteLine (b); 4 console.readline ();
Optional topics
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceExercises 3{classProgram {Static voidMain (string[] args) {Console.Write ("How many years have your mother been a stranger? "); stringA=Console.ReadLine (); Console.Write ("How old are you this year? "); stringb=Console.ReadLine (); intc = .; intD=int. Parse (a); intE=int. Parse (b); intF=c-d-e; Console.Write ("When you were born, your mother"+f+"years"); Console.ReadLine (); } }}
"2017-2-17" C # Fundamentals-Define variables, input and output