Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the members of C# Interface

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "example Analysis of C# Interface members". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Interface member definition description for C# interface programming:

The members of an interface are members inherited from the base interface and defined by the interface itself.

An interface definition can define zero or more members. Members of an interface must be methods, properties, events, or indexers. Interfaces cannot contain constants, fields, operators, instance constructors, destructors, or types, nor can they contain static members of any kind.

Define an interface that contains one for each possible category of members: methods, properties, events, and indexers.

The default access method for interface members is public. The interface member definition cannot contain any modifiers, such as abstract,public,protected,internal,private,virtual,override or static modifiers before the member definition.

Members of an interface cannot have the same name as each other. Inherited members no longer need to be defined, but interfaces can define members with the same name as inherited members. In this case, we say that interface members overwrite inherited members, which does not cause an error, but the compiler gives a warning. Turn off the warning prompt by adding a new keyword before the member definition. However, if members in the parent interface are not overridden, using the new keyword causes the compiler to issue a warning.

The name of the method must be different from the names of all properties and events defined in the same interface. In addition, the signature of a method must be different from that of all other methods defined in the same interface.

The name of the property or event must be different from that of all other members defined in the same interface.

The signature of one indexer must be different from that of all other indexers defined in the same interface.

The properties (attributes), return type (return-type), identifier (identifier), and formal parameter list (formal-parameter-lis) in the interface method declaration have the same meaning as those in the method declaration of a class. An interface method declaration does not allow you to specify a method body, and the declaration usually ends with a semicolon.

The accessor declared by the interface property corresponds to the accessor declared by the class property, except that the accessor body must usually use a semicolon. Therefore, the accessor is fully determined whether the property is read-write, read-only, or write-only.

The attributes (attributes), type (type), and formal parameter list (formal-parameter-list) in the interface index declaration have the same meaning as those declared by the class index.

In the following example, the interface IMyTest contains members such as index indicator, event E, method F, and property P:

Interface IMyTest {string this [int index] {get; set;} event EventHandler E; void F (int value); string P {get; set;}} public delegate void EventHandler (object sender, EventArgs e)

In the following example, the interface IStringList contains the interface for each possible type member: a method, a property, an event, and an index.

Public delegate void StringListEvent (IStringList sender); public interface IStringList {void Add (string s); int Count {get;} event StringListEvent Changed; string this [int index] {get; set;}}

Full name of the interface member of the C # interface programming

Interface members can also use full names (fully qualified name). The full name of the interface is made up of this. Add a dot to the interface name. " And then with the member name, for example, for the following two interfaces:

Interface IControl {void Paint ();} interface ITextBox: IControl {void GetText (string text);}

The full name of Paint is IControl.Paint,GetText and the full name of ITextBox. GetText . Of course, the member name in the plenipotentiary name must be defined in the interface, such as using ITextBox.Paint. It's just unreasonable.

If the interface is a member of the namespace, the full name must also contain the name of the namespace.

Namespace System {public interface IDataTable {object Clone ();}}

Then the full name of the Clone method is System. IDataTable.Clone .

This is the end of the content of "example Analysis of C# Interface members". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report