C # design basics
(i) C # project composition structure
- Project structure
. config---configuration file (storage configuration parameter file)
. csproj---Project files (manage file entries)
. SLN---Solution files (Manage projects)
. cs---Source file (program code)
- Four elements of a function
Name, input, output, processing
- Contents of the main function
Console.readkey (); Input statement
console.readline ();// Input Statement
Console.WriteLine ();// Output Statement
Console.WriteLine ();//Output statement
Namespace ConsoleApplication1 Namespace
Class Program
static void Main (string[] arges) method
- Precautions
Comments
Note: Tell the computer not to do it as a code.
1.//comment To line end, comment one line.
2./*SDFASDFASDF **/comments in the middle of the content, multiple lines.
(ii) Data types
- Common Key data types
Shaping: Integer type
Short Int16 2 bytes (16 digits)
Int Int32 4-byte (32-digit) value space is an integer maximum absolute value smaller than the mobile number one
Long Int64 8 bytes (64 digits)
Float Type: decimal type
Float single 4-byte assignment plus suffix F or f differs from double assignment
Double Double 8 bytes
Decimal decimal 16 byte Assignment range decimal part large so the range of assignments is not necessarily larger than the double range
Character type
Char Char 2 bytes Only one character can be placed, and only single quotation marks can be used
Boolean type Switch
BOOL Boomleam 1 bytes can only put ture or false, cannot be quoted
String Type Multiple Letter Strings
String String character Sequences to use double quotation marks
2 Escape Symbols
\ " Double quotes represents a double-quote character
\ \ counter Slash represents a backslash character "' \ '
\ r Enter (CR) To move the current position to the beginning of the bank
\ n line Break (LF) , move the current position to the beginning of the next line
\ t Horizontal Tabulation (HT) (Skip to next TAB location)
(iii) Basic type conversion
Automatic conversion: Automatic conversion If there is no data loss
Cast:
Add parentheses to the number on the left side of the converted value, and write in parentheses to be converted to that type float a= (float) 3.14
For strings:
Method One
int A=int. Parse ("string"); float b=float. Parse ("string"); double c=double. Parse ("string")
Method Two
int A=convert. ToInt32 (a); Float B=convert. ToSingle (b);
Practice Case One
static void mainstring[] args)
{
Console.WriteLine ("Little hi: What's your name?") ");
Console.Write ("I:");
String xm = Console.ReadLine ();
Console.WriteLine ("Small hi: Oh, so you are the" +xm+ "Ah, too! , what do you like to eat? ");
Console.Write ("I:");
string sw = Console.ReadLine ();
Console.WriteLine ("Small hi: I also like to eat" +sw+ ", you can eat how much ah?) ");
Console.Write ("I:");
String sl = Console.ReadLine ();
Console.WriteLine ("Small hi: you actually eat" +sl+ ", than I eat a lot of");
Practice Case II
Console.WriteLine ("Please enter a number:");
String a = Console.ReadLine ();
Console.WriteLine ("Please enter another number:");
String B = Console.ReadLine ();
Console.WriteLine (Convert.ToInt32 (a) +convert.toint32 (b));
Console.WriteLine (int. Parse (a) + int. Parse (b));
C # design basics