[Aaronyang] C # People love to learn not to learn [1]

Source: Internet
Author: User
Tags switch case

1. Notepad write C #, out of VS

Create a new Notepad with the name HelloWorld.cs

using System; namespace hello{    publicclass  helloworldsay{        staticvoid Main () {            Console.WriteLine (" Hello, World ");            Console.ReadLine ();             return ;        }    }}

Simply compile with the CSC command:

My directory is in: C:\Program Files (x86) \microsoft Visual Studio 12.0\common7\tools\vsvars32.bat

Input command: csc/out: Output directory and file name (. dll or. exe) source code file

csc/out:f:\net\2014 year December 25 003728\helloworld.exe F:\net\2014 December 25 003728\helloworld.cs

Common and Csc/t:library source code files are compiled into DLLs

Csc/t:exe source code files compiled into EXE

Csc/t:module Source code files

Csc/t:winexe Source code files

/R used to specify the referenced DLL

Source code main portal file can be *.cs represents all CS files under the compiled folder

or generate an XML file-"CSC source code file/doc: path + file name. xml

or/main: Specify which method to use as the entry point for the program

Of course there are other forms, not specifically introduced, although you seem useless, but to give a real case: The project continues to release software, are to pull the SVN code itself, and then automatically compiled, or Web page developers themselves point of compiling, now feel useless?

2. Value types and reference types, unpacking and boxing I think the better explanation, the limits of the struct

These two kinds of data are stored in different places in memory. Value types are stored on the stack, and the reference type is stored on the managed heap, referred to as the heap, and the reference address is stored.

The essence of unboxing and boxing: a series of move operations that value types throw on stacks and heaps when transitioning to System.Object. Boxing: Value types are copied from the stack onto the heap, while unpacking is copied from the heap onto the stack. So it has an impact on performance.

Here's a ay=null to show that Ay is a reference type, indicating that it does not reference any object

In addition to some well-known types, focus on struct value types and class reference types

Structs can have properties and methods, but without inheritance, structs can override System.Object's virtual methods, but they cannot define new virtual or abstract methods. You cannot have an parameterless constructor, and you cannot define an initial value for a member variable. But the performance is good, the function of class is more.

Classes and structs are actually templates that create objects.

3. Learn more about CTS

3.1 Enumerating some value types

1. Integral type (from fewer bits to multiple permutations 8,16,32,64) signed (sbyte,short,int,long) unsigned (byte,ushort,uint,ulong), each of which corresponds to a type in the CTS, such as a long Correspondence System.Int64

2. Floating point (from fewer bits to multiple permutations 32,64) float (CTS:System.Single) 32-bit single-precision floating-point number double (CTS:System.Double) 62-bit double-precision floating-point numbers, such as float ay=12.3f,double Ay1=12.3e2,e2 represents 10 of the index is 2, is 12.3 times 10 of the 2-time Square

Decimal (CTS:System.Decimal) 128-bit high-precision decimal number notation, followed by a number m for decimal

3.bool (CTS:System.Boolean)

4.Char (CTS:System.Char) 16-bit (Unicode) characters

5. Enumerate enum

3.2 Enumerating Some reference types

Object,string, etc.

Here the string is very special, is a reference type, for example, 2 string reference a string address, when S1 modify the value, s2 no change, because modify a string, will create a completely new string object, do not believe can run the following example. String is a special type of reference and is essentially the result of operator overloading

  string " S1 " ;             string s2 = S1;            Console.WriteLine (s1);            Console.WriteLine (S2);            S1"newS1";            Console.WriteLine (s1);            Console.WriteLine (S2);            Console.ReadLine ();

Effect:

4.c# Jump statement, except Break,continue,return and goto

Goto does not just jump to the specified label, it can also be used in a switch case to jump to the specified case

Jump the way of the label, not here to speak.

4. Namespace:: Double colon (global action)

All know can nest with each other namespace, to namespace alias operation, double colon mention it

Here:: The effect is the same as the dot, but I'm not saying it's a substitute for a point number.

Preprocessor commands for 4.c#

You must have used it, for example #region #endregion

1. #define and #undef, such as #define DEBUG, are often used in conjunction with other preprocessor.

2. C # also includes many, such as # if #elif (equals else if) #else #endif, such as #if debug #endif indicates that the following code is executed if the project is in DEBUG mode.

3. #warning the "warning test" #line #pragma

5. You may not know the colon way to call a method with a default value (. NET framework4.0 +)

6. In a property, you can add an access modifier to the

7. The temper of the static constructor

Static class name {}

You cannot have an access modifier, and a static constructor runs at most 1 times. That is, it is called before the code references the class.

Cannot take arguments, and a class can only have 1 static constructors. Only static members of a class can be accessed, and instance members of the class cannot be accessed.

He can coexist with parameterless constructors. In a static constructor, you can assign a value to the external static readonly field

The constructor provides the constructor initializer, which is called with this or base.

For example, public A (String des): Base (des,4) {}

8. WeakReference weak reference with the default strong reference 9. This chapter skips sections of keywords that you might want to know about: readonly and const, ref and out, partial classes, deep copy with shallow copy (if the class is copied, if the class references another class, he is just an address, no replication.) Finally the address of the object to be copied back again), GC garbage Collection, c#4.0 expansion method, these regular, not said

[Aaronyang] C # People love to learn not to learn [1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.