C # fourth time job

Source: Internet
Author: User

The teacher first introduced the difference between the structs and the class.

1. Structs is value types.
2. Structs can be instantiated without using a new operator. Structs can declare constructors, but they must take parameters, can not declare default Constructor-compiler would provide One & no destructor.
3. A struct cannot inherit from another struct or class, and it cannot be the base of a class. It is inherit from the base class Object. A struct can implement interfaces.
4. Within a struct declaration, fields cannot is initialized unless they are declared as const or static.

The format for defining strcts is as follows

And then I tried it myself. Defining a struct

Then the teacher explained to us the interface:

1. An interface was a contract that guarantees to a client how a class or struct would behave.

2. When a-class implements an interface, it tells any potential client "I guarantee I'll support all the methods, Properti ES, events, and indexers of the named interface. "

3. These contracts is made manifest (indicated) using the interface keyword, which declares a reference type that encapsulates th E contract.

The format for defining interface is as follows

I've also tried to define a interface.

Then the teacher identified the abstract Class, Interface and Mix-ins

1. An interface offers a alternative to a abstract class for creating contracts among classes and their clients.

2. The difference is so abstract classes serve as the top of a inheritance hierarchy, where as interfaces may add their contract to numerous inheritance trees.

Then I created a class to inherit this interface.

It would be nice to have multiple interfaces listed directly in the back, but it's worth noting that each interface is defined at the time of inheritance.

And we can also inherit in the interface and interface, this is relatively broad, can be one to the other can be many.

C # fourth time job

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.