C# Interface as DataType -


hi guys im trying learn interface. got basic knowledge it, contract class. bit confuse interface data type.

question: purpose of using interface datatype.

ex.

ienumerable folders {get;}  

or

icomparable compare {get;} 

if im correct ienumerable interface. value type saved @ (if there any)?

thx

it means data type can reference object of class implementing interface.

ienumerable thing = new list(); works

ienumerable thing = new collection(); works

ienumerable thing = new hashset(); works

in case, you don't need know exact type assigned object, you want type implements contract

for example, ienumerato implement getenumerator() allow use foreach

foreach (var elem in thing) work whatever type thing, needs implement ienumerator.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -