Interface 2_C #

Source: Internet
Author: User

Interface:

Definition: an interface is a name set composed of one or more abstract members related to semantics. The interface indicates the actions that must be supported by the specified class or structure.

-> The interface contains members without access modifiers (because all interface members are implicitly set to public and abstract.

-> All the Members defined in the interface must be implemented in the class or structure to implement it.

Comparison between interfaces and abstract classes:

-> Similarities: When a class is derived from an abstract base class, it must implement the details of the abstract method (if the derived class is not declared as abstract)

-> Differences: abstract base classes can not only define a set of abstract methods, but also specify public, private, and protected state data and many entity methods that can be accessed by quilt classes.

How can I dynamically determine the interfaces supported by a type?

1. Explicit forced conversion: IPointy a = (IPointy) B; requires structured exception handling; not recommended.

2. as keyword (get interface reference): You can get a reference pointing to this object interface in the statement using this keyword; otherwise, a null reference with a value of null will be returned.

IPointy a = B as IPointy; if (! = Null) {} else {}

3. is keyword (get interface reference): If the object to be checked does not match the specified interface, false is returned.

If (B is IPointy) {} else {}

Explicit interface implementation:

-> You cannot add access modifiers when defining explicit implementation members.

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.