Beginner
Recently had the opportunity to speak C #, beginners easy to make some mistakes, perhaps we these old birds usually will also ignore. If you have time, you will tidy up some.
1. @ In use:
In many languages, the @ is often referred to as the address before the variable, and @ in C # is used in front of the string variable, which means ignoring all the escape characters "\" in the string. Such as:
Console.writeln ("C:\\downloads\\test.rar");
Equivalent to the following statement:
Console.writeln (@ "C:\downloads\test.rar");
2. Differences between convert.to* and var.to* usage
All of the above two functions are explicitly variable type conversions, which are generally used for variables that cannot be implicitly converted, using the following examples to notice their differences.
int intext = 1999;
string sttext = "";
Sttext = convert.tostring (intext); //Convert syntax examples
Sttext = Intext.tostring (); //Note that the variable is directly to the new type of usage, the latter () is not to be saved, which is different from some languages
Console.WriteLine ("This is convert test string:" + Sttext);
3. The difference between C # 's switch and C + +
Grammar:
Switch(VAR)
{
CaseVarvalue1:
< statement group >
Break;
CaseVarvalue2:
< statement group >
Break;
......
CaseVarvaluen:
< statement group >
Break;
default://default can be omitted
< statement group >
Break;
}
C # and C + + have the same switch syntax, but C + + allows the case statement to be run down, that is, when the break is omitted, the following set of box statements is continued, and the usage is prohibited in C #. In C # 's switch statement, the break is not small, but you can skip it in the way of Goto case Varvalue and execute the following case statement group directly. Examples are as follows (perhaps the example is not logical, just to show how C # is running through the switch):
Console.WriteLine ("This is convert test string:" + Sttext);
int var1 = Convert.ToInt32 (Console.ReadLine ());
Switch (VAR1)
{
Case 70:
Console.WriteLine ("The number is!\n");
Goto Case 80; //Take case 80 as a goto label
break;
Case 80:
Console.WriteLine ("The number is!\n", var1);
goto default;
break;
default:
Console.WriteLine ("The number is not" or "!\n");
break;
}