Question

How an Interface like IEnumerable or IQuerable can store data into itself?
or for example where this Tables go on `IQueryable?
and How can I have an Interface like that for myself ?

public Interface IMyNumerator<T>  
{

}

IMyNumerator<int> mynumbers;

how can I fill mynumbers with some Int values ??

Was it helpful?

Solution

The interfaces themselves do not contain data. Although you may see IEnumerable as a type when using a collection, the underlying object is always of a specific type implementing this interface.

The object actually containing your data may be of any type implementing that interface. Please refer to:

And if you would like to implement your own version of IEnumerable, inherit from the interface . Try searching for "A Beginners Tutorial on Implementing IEnumerable" on codeproject ;-)

OTHER TIPS

An interface never stores data. An implementation does. Whenever your code sees an object of type IEnumerable, its actual dynamic type is something else, like a ListIterator or so. If you want to have your own type implement IEnumerable you can just do that. Usually, you'll have an embedded (private) class that implements the enumerator for a collection, though.

Interfaces define, well interfaces.

You can see it as defining a Contract, that explains how to work with a specific concept. Behind the interface is an actual Implementation, for example a Database Connection.

In computer science, an interface is the point of interaction with software

To make it a bit more simple, consider this in the hardware world.

USB defines an interface to things, it has a specific shape so it can go into a specific plug, and it has "protocols" of how to talk with a USB device.

An behind this "interface" you can have, just about any device. Fx. a camera or a storage device.

Well this is a very confusing question but I'll try anyway.

IEnumerable is an Interface that only describes public methods / properties, it does not describe how data is stored.

The implementer of this interface is responsible to store the data and can do so in any structure that suits the need.

You can have an interface like that by yourself by either implemented it or defining another interface that you use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top