Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am a beginner c# developer. I converted from php to c# recently. From my previous knowledge, and the one I acquired while learning c#.. I know interface contain method definitions and other property definitions. But I constantly see people using the Ienumerable interface like a class. This is really confusing me. I don't know whether I learnt wrong, or I didn't pay attention or I am going mad. somebody please with an example, can you please explain it to me.
Posted
Comments
Sergey Alexandrovich Kryukov 20-Aug-15 0:14am    
How, how it's possible to ask such questions? When you look at the definition, it's explicitly written what it is. I have only one idea about it: you have no clue what is runtime type (vs. compile-time type) and what is interface and its purpose. If so, you are lost, have to read on OOP from the very beginning. It would take too much time for a Quick Answer to explain you all the basics at once.
—SA
Ralf Meier 20-Aug-15 0:50am    
@Sergey:
The inquirer wrote, that he is a beginner - so I think this question is excusable and not a "bad mistake" ... Everything must be learned somehow and at some time ...
Sergey Alexandrovich Kryukov 20-Aug-15 0:55am    
Did I say anything against that? That's why I suggest to start reading on OOP from the very beginning.
—SA
ayhanUGUR 20-Aug-15 6:16am    
ıt is an interfaces

1 solution

Please see my comment to the question. Yes, this is interface, and no, people don't use it as a class, it's impossible.

My idea is that you only think that some "use it as a class", because you don't know how interfaces are used and how inheritance works. A variable or a member can have different runtime type and compile-time type. If some interface is implemented, the runtime type is always a class or struct. However, the declared (compile-time) type can be the interface type, because it is, due to inheritance, is assignment-compatible with the type implementing the interface.

I think this is enough. Feel free to ask some follow-up questions, if you have to, but keep in mind: if something is unclear at this point, the best idea would be reading on OOP from the very beginning. Only when you get all major concepts, with examples, you can understand this:
https://msdn.microsoft.com/en-us/library/ms173156.aspx[^],
https://msdn.microsoft.com/en-us/library/hh165754%28v=nav.70%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900