C # variables

Source: Internet
Author: User

Use of variables

A variable is a name that represents the data stored in memory when the program executes, and is used for program Access data.

Variable declaration

Before you can use a variable, you must declare it: give the variable a name and associate a type, and let the compiler allocate a chunk of memory for it. (A long piece of crap)

  string name; // A variable is declared, the name is named, and the type is string

You can also put multiple variable declarations in a single statement, but must be of the same type, with a comma interval between them.

  

Types of variables

Local variables save temporary data at method scope

field holds data related to type or type instance, is a member of type

parameter is used for one method to pass data to another method temporary variable

A member of an ordered set of data of the same type of an array element

Variables that can be initialized automatically
1     class Program2     {3         Static intNumber//class field4         Static voidMain (string[] args)5         {6 Console.WriteLine (number);7             byte[] Arrs =New byte[4];8Console.WriteLine (arrs[1]);//array elements9Anystruct any=Newanystruct ();TenConsole.WriteLine (Any.field);//structure Field One         }   A     } -  -     structanystruct { the         Public Doublefield; -}

C # variables

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.