C # Course Notes.
Lesson 1
. Net Technology
Windows console Program
1. WinFrom program: Windows program such as QQ.
3. ASP. Net: Develop website programs. For example, WebFrom Development
4. Embedded Development is also available. . Net.
5. WCF: communication programs such as QQ. WF workflow.
Lesson 2:
Console Program
Console. WriteLine ("enter an integer: \ n"); // print a line of string equivalent to printf ();
String s = Console. ReadLine (); // equivalent to scanf (); used to receive strings.
Int I = Convert. ToInt32 (s );
Int i1 = I + 10;
Console. WriteLine ("{0}", i1 );
String s1 = I. ToString (); // string s1 = Convert. ToString (I );
Console. WriteLine (s1 );
Console. ReadKey (); // This line of code is used to prevent
Lesson 3:
Speaking of the naming rules for C # variables, there is no big difference with C. Basically the same.
Lesson 4:
In C #, the addition, subtraction, multiplication, division, and operation rules are not much different from those in C. However, the addition of C # can be applied to strings.
For example, string s = "Hello"; string s1 = "Wrold"; string s2 = s + s1; so string s2 = "HelloWrold ";
String s = s1 + s2 + "hahah ";
And I ++; is auto-increment. Similar to C.
Lesson 5: assign values.
I = 3; j = 5;
Temp = I; I = j; j = tmep;
Lesson 6:
Boolean operation
Equal judgment: = do not confuse with =.
Not equal :! =
Bool B = true; reverse! B;
I = 3; j = 4; and &&. Or |. In C #, single & single | can also be and, or operator. However, they do not provide short-circuit operations. & | Short-circuit computation is available. High efficiency. Therefore, we usually use double & double |.
(I> = 3) & (j <4) Flase.
Lesson 7:
Trielement operation:
If statement: the format is the same as that of C. The input and output formats are different.
Console. WriteLine ("please input your age :");
Int age = Convert. ToInt32 (Console. ReadLine ());
If (age> 18)
{
Console. WriteLine ("promit to see the film ");
}
Else
{
Console. WriteLine ("forbit to see the film ");
}.
If ()
{}
Else if ()
{}
Else
{}
In C #, you can use = to determine whether a string is equal. If true, the string is equal.
For example:
String ps = Console. ReadLine ();
If (ps = "888888 ")
{
Console. WriteLine ("right ");
}
Else
{
Console. WriteLine ("flase ");
}
Lesson 8:
This lesson is a comments on assignments. It is skipped because the assignments are relatively simple.
Lesson 9: describes how to use a switch. His difference from C is that break must be used later in case. It cannot be omitted. After executing a case block, you must exit the switch.
Lesson 10:
Loop statement: while do while.
Lesson 11th:
Loop interruption
Use break continue.
Use while continue to calculate 1 ~ The sum of the numbers except the multiples of 7 between 100.
Use while and break to enter the user name and password.
Lesson 12th:
For Loop statement
For (int I = 0; I <10; I ++)
{
If (I = 3)
Continue;
Console. WriteLine ("I = {0}", I );
}
In the for loop, do not worry about where I ++ is, I ++ will be executed.
This is better than while.
When I = 3 is set, the function of the continue statement is to skip the statement after the continue and skip the I ++ statement directly.
The next step is to jump to the cycle.
Lesson 13th:
Type conversion:
It can be divided into implicit conversion and explicit conversion.
If the target type is sufficient for source type conversion, implicit conversion is required. If the target type does not necessarily meet the requirements of source type conversion, explicit conversion is required.
The value range of variable types such as byte int can be byte. MinValue ~ Byte. MaxValue.
The value range of Byte is 0 ~ 255. The int range is much larger.
Therefore, when byte B; int I; if I = B; is an implicit conversion, because I must include the value of B.
If B = I;, the compilation fails. An explicit conversion is required. B = (byte) I;
Cast is a type conversion at the memory level. The data in the memory remains unchanged, but the viewing angle is different.
Therefore, cast conversion can be performed only when there is an intersection in the memory storage. For example, int long. All are numbers. However, sting int values cannot be converted.
Convert
It is no longer a memory-level conversion.
Converts a string to data and data to a string.
String s =" 12" ;
Int I = Convert. ToInt32 (s );
Or
Int I = 20;
String s = Convert. ToString (I );
Lesson 1
Enumeration
Enum Dir {south, north, east, west}
Dir d = Dir. south.
Lesson 15:
Array:
Int [] nums = {5, 3, 8}; // declare and initialize the nuns array.
String [] names = {"tom", "jerry", "jam "};
Int [] nums1 = new int [5]; // The nums1 array has five elements.
Int [] nums1 = new int [5] {1, 2, 3, 4, 6. But few people have such abnormal statements.
Look at this function: new cyclic Function
Int [] nums = {5, 3, 8, 2, 1 };
Foreach (int n in nums) // traverses each number in the array and assigns it to n
{
Console. WriteLine ("{0}", n );
}
Lesson 16: Functions
The function is written at a time and called repeatedly. Simplified code.
Static void PrintName () // void indicates that no return value is returned.
{
Console. WriteLine ("Please input your name :");
}
Class 17:
Function parameters: pass a value to the function, dynamically changing the value required within the function.
Parameter array:
Let's look at this function: What's the difference with the last one?
The difference is that there is one more params in the function parameter. Dynamic parameter, because the number of this parameter is uncertain. Therefore, C # packs uncertain parameters into an array.
There can be other fixed parameters before a variable parameter, but no other parameters later. There can only be one params parameter.
The default value .. Net4.0 only.
Class 18: function overloading:
Can the function names be the same in C? The answer is yes. However, it is conditional. The type or number of parameters of a function must be different.
Lesson 19: string processing:
Let's look at the following functions:
Take a look at the following functions:
Use of function Split:
Use of the Replace function:
Function Substring: extract a specified string.
This function has two overloaded functions, one and two parameters.
Function Contains: determines whether a string Contains a specific string and returns a Boolean value.
Function EndsWith () to determine whether the string ends with a string.
Similarly, StartsWith () is used to determine whether a string starts with a string.
The Indexof () function returns the position of the given string in the main string, starting from the nth character.
The LastIndexof () function returns the position of the given string in the main string.
Functions of PadLift () and PadRight () are as follows:
Lesson 20: exercises:
The ref parameter of the function, which is passed by reference. The variable value is changed within the function. The first called function does not change the value of the variable in the main function. The value is transferred. The second is the transfer of references.
Function parameter out assigns an initial value to the variable within the function.
Lesson 21: The Role of variables.
22: debugging:
Continue, breakpoint, condition breakpoint, and hit count breakpoint.