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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 9, 2014, 11:56 PM EDT
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.
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 10, 2014, 12:27 AM EDT
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
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 10, 2014, 1:20 AM EDT
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