where C # syntax needs to be noted

Source: Internet
Author: User

Some C # grammatical problems encountered in the written test, because it is seldom used, the test is ambiguous, now make a note.

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceLeetcode8 {9 Ten     /*examples of static constructors*/ One     class Person A     { -         /*static constructors do not allow access modifiers*/ -         StaticPerson () the         { -Console.WriteLine ("I am a static constructor!!! "); -         } -  +  -         /* + There are a few things to keep in mind when using static constructors: A  at 1. Static constructors have neither access modifiers nor parameters. Because it is. NET calls, so modifiers like public and private are meaningless.  -      - 2, is when the first class instance is created or any static member is referenced. NET will automatically call the static constructor to initialize the class, which means that we cannot call the static constructor directly, and we cannot control when the static constructor is executed.  -  - 3. A class can have only one static constructor.  -  in 4. Parameterless constructors can coexist with static constructors. Although the parameter list is the same, one belongs to the class and one belongs to the instance, so there is no conflict.  -  to 5, run up to one time only.  +  - 6. Static constructors cannot be inherited.  the  * 7. If a static constructor is not written, and the class contains a static member with an initial value set, the compiler automatically generates a default static constructor.  $          */Panax Notoginseng     } -  the  +  A     /*Example of readonly initialization*/ the     classSample +     { -         //ReadOnly modified can be assigned multiple times at initialization time. $          Public ReadOnly intReadonlyvalue = -;/*First time Assignment*/ $          PublicSample (intvalue) -         { -              This. Readonlyvalue = value;/*Second Assignment*/ the         } -     }Wuyi  the  -     /*static readonly and const*/ Wu     classFruit -     { About          Public Const intcolor =9;//access directly through the class name $          Public Static ReadOnly stringType ="Watermelon"; -         /*s - Public Fruit () -         { A type = "banana";//cannot be assigned in a normal constructor +         }*/ the  -         StaticFruit ()//You can assign a value in a static constructor $         { theType ="Apple"; the         } the     } the     /* - The const and static readonly are really like: access through the class name, not the object name, read-only in the program, and so on. Can be mixed in most cases.  in The difference between the two is that the value of the const is determined during compilation, so its value can only be specified by a constant expression at the time of declaration.  the      */ the}

where C # syntax needs to be noted

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.