C #3.0 Study Notes (4) structure struct

Source: Internet
Author: User

 

1. What is structure?

 

A: The structure is a data type defined by a programmer. It is very similar to a class.

 

2. What are the differences between structures and classes?

 

1. The class is the reference type, and the structure is the value type.

 

2. structures are implicitly sealed, so they cannot be derived.

 

Iii. Structure declaration Syntax:

 

Struct StructName

 

{

 

Statement;

 

}

 

Note: 1. struct declares the structure keyword.

 

2. StructName is the structure name.

 

4. What is the structure declaration and instantiation call?

 

The Code is as follows:

 

Class Program

 

{

 

Static voidMain (string [] args)

 

{

 

Simple s1 = new Simple ();

 

Simple s2 = new Simple (5, 10 );

 

Console. WriteLine ("the value of letter creation using simplified method is: {0}, {1}", s1.x, s1.y );

 

Console. WriteLine ("the value of component build function is {0}, {1}", s2.x, s2.y );

 

Console. ReadKey ();

 

}

 

}

 

Struct Simple

 

{

 

Public int x;

 

Public int y;

 

Public Simple (int a, int B)

 

{

 

X =;

 

Y = B;

 

}

 

} Www.2cto.com

 

The program output result is:

 

0, 0

 

5, 10

 



The author's wheat forever.

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.