IEnumerable and IComparable
give difference between IEnumerable and IComparable with real time example.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Apr 10, 2014, 5:20 AM
Definition
IEnumerable
public IEnumerator GetEnumerator();
IEnumerator
public object Current;
public void Reset();
public bool MoveNext();
for example go this link
for IComparable go to this link
Abhay ShankerPosted Apr 10, 2014, 4:27 AM
IComparable is implemented by types that you wish to give them the ability to compare themselves to other instances of the same type, when sorting for example.
IComparer is implemented by a type that you wish to use as a sorting predicate when sorting a collection. This allows you to create several classes that will compare the same two instances in different ways thus creating a different sort order.
Array.Sort will use each element's IComparable implementation to sort the values or it can receive an IComparer to choose the order.
For more information read How to use the IComparable and IComparer interfaces in Visual C#
IEnumerable is an interface that represents the ability to iterate through the collection using an iterator. For example, anything that implements IEnumerable can be iterated through using a for-each loop. Both the Array and List
It isn't a collection in itself, it just represents a behaviour that actual collections may (and usually do) have.
The generic equivalent of IEnumerable (IEnumerable
Jignesh TrivediPosted Apr 10, 2014, 3:56 AM
both are used for different purpose....
so I think there is no comparison between these two.
IEnumerable can be used by the foreach statement.IComparable objects are indeed comparable and used create comparison logic between objects.
http://support.microsoft.com/kb/320727
hope this will help you.