c#3.0 var keyword

Source: Internet
Author: User

Important conditions for using the VAR keyword:

<1> can only be used for local variables and cannot be used for fields.

<2> can only be used when initialization is included in a variable declaration.

<3> once the compiler infers the type, it is fixed and cannot be changed (this does not know what it means).

Access modifiers:

<1>private: The default access level

<2>public

<3>protected

<4>internal

<5>protected Internal

Local constant: Local variable once it is initialized, its value cannot be changed, just as local variables, local constants must be declared inside the block. The two most important characteristics of a constant are the following (the thing that writes this constant is because in writing a C # program, I have never defined a constant, and now I'm going back to rewriting learning C # Basics):

<1> constants must be initialized in the declaration.

<2> constants cannot be changed after they have been declared.

The core declarations for constants are as follows:

<1> Add the Keyword const before the type.

<2> must have initialization statements. The initialization value must be determined at compile time, usually a predefined simple type or an expression consisting of it, which can also be a null reference, but it cannot be a reference to an object because the object's reference is determined at run time (the object's reference, the new keyword that corresponds to the instance name of the class, to the memory request reference (address). A const is not a modifier, but a part of a core declaration that must precede a type.

Const Type Identifier=value;

c#3.0 var keyword

Related Article

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.