1. You can use the csc.exe compiler to compile the source file.
- The most convenient way is to start running-> Program-> VS Tools-> VS command prompt
Run in the directory:
Csc fileName. cs
- Or, after the corresponding environment variables are configured, run the preceding command in the cmd window.
- To compile the file into a dll:
Csc/t: library fileName. cs
- If you want to introduce dll during compilation:
Csc fileName. cs/r: dllName. dll
2. C # variable names are case sensitive 3. C # handle "uninitialized variables" as errors
- Variables are fields in a class or structure. If Initialization is not displayed, the default value is always initialized when these variables are created.
- A variable is a local variable of the method. It must be initialized before it can be used. Otherwise, an error occurs.
4. Declare a variable to create only a reference for the object. But this reference does not point to any object (different from c ++) 5. Scope conflict of Variables
6. Constants
- Constants must be initialized during declaration.
- The initialized value cannot be extracted from a variable (if you want to do so, use a read-only field)
- Constants are always static and cannot be modified using static
- Example
Const int a = 100;
7. Value Type and reference type
- Value Type: stored on the stack
- Reference Type: stored on the managed stack (mutual value assignment only modifies the reference and does not generate another value)
8. String
9. Switch statement
10. The foreach loop cannot change the values of items in the set. To change the values, use the for loop 11. goto jump statement.
12. Enumeration type
- Example
using System;namespace Wrox.ProCSharp.Basics{public enum TimeOfDay{ Morning = 0, Afternoon = 1, Evening = 2} class EnumExample{ public static int Main() { WriteGreeting(TimeOfDay.Morning); return 0; } static void WriteGreeting(TimeOfDay timeOfDay) { switch(timeOfDay) { case TimeOfDay.Morning: Console.WriteLine("Good morning!"); break; case TimeOfDay.Afternoon: Console.WriteLine("Good afternoon!"); break; case TimeOfDay.Evening: Console.WriteLine("Good evening!"); break; default: Console.WriteLine("Hello!"); break; } }}}
- Extract enumerated values from strings
TimeOfDay time = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "afternoon", true); Console.WriteLine((int)time);