C # interface basics,

Source: Internet
Author: User

C # interface basics,

The interface only contains the signature of the method, attribute, event, or indexer.. The class or structure that implements the interface must implement the interface member specified in the interface definition.

Can the interface contain fields?

When I was asked this question for the first time, I was stunned. I can only answer: I have never seen variables defined in interfaces, But I just defined some behaviors and contracts, obviously, the answer to this question is ambiguous !!! Why?

I personally verified it. For example, if it proves that my impression is correct..., I am glad that I am. Maybe cainiao only has this pursuit,

But why?

 

The first is an article from a senior in CSDN. Click to enter.

This is a good description, so you can extract it for better understanding.

 

Interfaces describe rules and are used to define contracts and constraints. constraints are for behaviors;

Interfaces can define attributes, methods, index indicators, and events;
But it cannot contain constants, fields (fields), operators, constructors, and destructor, and it cannot contain any static members;

An interface cannot exist independently and cannot be instantiated just like an instantiated class;

The field must be allocated for memory instantiation;

Besides, the interface cannot contain any code (including fields?) that implements its members ?);

Only members can be defined. The implementation process must be completed in the class that implements the interface.

 

At this point, I finally found a better answer to this question. If not, please correct me.

 

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.