Interface implementation in c# — is it possible to use a different name for the property/method?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
16 views
What was clear from where such a question: after a long experience in vb.net (as my first language) recently I had the need, and most importantly - the opportunity to learn C# (version 7.0) At the same time, having experience with JavaScript, specific difficulties with the development of c# syntax, I did not have. Of course, yet constantly make analogies with vb.net because I often lack many of its features, which is missing in C# a priori. And now, about one of the features I would like to ask the experts.

On vb.net defined this interface:
"'Defines an object that is an element of the enumeration"'The type of identifier for the itemPublic Interface IEnum(Of T) "'The ID of the enumeration elementReadOnly Property ID As T 'and so on... End Interface

In implementations of this interface, set the ID I can assign a different name, which is semantically more close to this specific implementation and it will look like this:
"'IndustryPublic NotInheritable Class Industry : Implements IEnum(Of Byte) "'Code branch directionsPublic ReadOnly Property Code As Byte Implements IEnum(Of Byte).ID 'and so on... End Class

or, in another implementation:
"'Field of activityPublic NotInheritable Class Employment : Implements IEnum(Of Integer) "'Type sphere of activityPublic ReadOnly Property Type As Integer Implements IEnum(Of Integer).ID 'and so on... End Class

Like, defining the same interface in c#, I can implement it in classes to use a different name for the property (in this case for the property ID's)?
by | 16 views

3 Answers

0 like 0 dislike
_ public interface IId { int ID { get; set; } } public class Element : IId { public int Type { get { return ((IId)this.)ID; } } int IId.ID { get; set; } }
by
0 like 0 dislike
The idea is to clearly identify the property interface, which returns the specified property of a class. In this case, the access property of the interface by its name will only be interface. Class will access its value.

/// Defines an object that is an element of the enumeration/// The type of identifier for the itempublic interface IEnum{ /// The ID of the enumeration elementT ID { get; } // and so on... } /// Industrypublic sealed class Industry : IEnum{ /// Code branch directionspublic byte Code { get; private set;} byte IEnum.ID => Code; // explicit interface implementation // and so on... } /// Field of activitypublic sealed class Employment : IEnum{ /// Type sphere of activitypublic int Type { get; private set;} int IEnum.ID => Type; // explicit interface implementation // and so on... }
by
0 like 0 dislike
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Apr 11, 2019 by pavelkarinin
110,608 questions
257,186 answers
0 comments
35,534 users