C # Basic Grammar review-use enumerations and structs to create value types

Source: Internet
Author: User

Declaring enumerations:

Enum Season{spring,summer,fall,winter}

If you do not specify a constant integer type for enumerating an enumerated literal constant, the compiler automatically assigns a value to him that is older than the previous enumerated literal constant.

Enum Season{spring=1,summer,fall,autumn=fall,winter}

Select the basic type of enumeration:

Enum Season:short{spring,summer,fall,winter}

Declaration structure:

struct TIME

{

private int hours,minutes,seconds;

Public time (int hh,int mm,int SS)

{

hours=hh%24;

minutes=mm%60;

seconds=ss%60;

}

public int hours ()

{

return hours;

}

}

Understand the differences between structs and classes:

You cannot declare a default constructor for a struct, the compiler always declares a constructor for us, the default constructor always initializes the field to Null,0,false, and if you write a non-default constructor, all fields are initialized;

The class can be declared again when an instance field is initialized, but is not allowed in the structure;

To copy a struct variable:

If the struct variable on the right is fully initialized, it can be copied directly to the left;

C # Basic Grammar review-use enumerations and structs to create value types

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.