In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how the C# interface is defined and inherited. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
C # interface definition
C# does not support multiple inheritance, but there are more cases of multiple inheritance in the objective world. In order to avoid the complexity of the program caused by traditional multiple inheritance, C # puts forward the concept of interface. The function of multiple inheritance can be realized through interfaces.
The class or structure that implements the interface should be strictly consistent with the definition of the interface. An interface describes a set of related behaviors that can belong to any class or structure. An interface can consist of methods, properties, events, indexers, or any combination of these four member types. The interface cannot contain fields. Interface members must be public.
Classes and structures can inherit from interfaces in the same way that classes inherit base classes or structures, and can inherit multiple interfaces. When a class or structure inherits an interface, it inherits the member definition but not the implementation. To implement an interface member, the corresponding member in the class must be public, non-static, and have the same name and signature as the interface member. The properties and indexers of a class can define additional accessors for properties or indexers defined on an interface. For example, an interface can declare a property with a get accessor, while a class that implements the interface can declare the same property with both get and set accessors. However, if the property or indexer uses an explicit implementation, the accessor must match.
Interfaces can inherit from other interfaces. A class can inherit an interface multiple times through the base class or interface it inherits. In this case, if the interface is declared as part of a new class, the class can only implement the interface once. If the inherited interface is not declared as part of the new class, its implementation is provided by the base class that declares it. The base class can implement interface members using virtual members, in which case the class that inherits the interface can change the interface behavior by overriding the virtual member.
Define Interfac
The declaration of the interface is in the following format:
Modifier interface interface name: inherited interface list {interface content;}
All of them are optional except interface and interface name. The following is an example of a C# API definition. The code is as follows:
Public interface iSomeInterface {void UpdateDataBase ();}
Interface inheritance
An interface can inherit from one or more base interfaces. For example:
Interface iOthrerInterface: iSomeInterface,iCom {int CompareTo (object obj);} Thank you for reading! This is the end of the article on "how to define and inherit the C# interface". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.