Often I can see a statement like this: "IEnumerable: Represents a collection of objects ....".
- What is a collection in terms of the selected programming language, for example, CSharp?
- Do you think that IEnumerable is a collection?
Often I can see a statement like this: "IEnumerable: Represents a collection of objects ....".
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
Mariusz PostolRank #650 · 3.7K reputationPosted Aug 23, 2024, 5:10 AM EDT
"In C#, a collection is a class that holds and manages multiple objects" - arrays for example comply with this definition but are collections? We cannot define the collection term using the collection word!!?
"...holds and manages multiple objects." - a class cannot manage any object because it is compile-time text but the objects are instantiated at run time.
Sorry, but it doesn't clear things up!
Mariusz PostolRank #650 · 3.7K reputationPosted Aug 23, 2024, 3:42 AM EDT
@Gowtham Cp - I am looking for an answer that allows us to avoid discussion on the meaning of the "way" word in terms of the language. for example. Let me stress in terms of a programming language but not in terms of natural language. It is like mathematics, but not sociology, for example, because CS and IT were derived from mathematics. There must be no doubts.
You said "IEnumerable isn’t exactly a collection" but I know authors stating something different.
Sorry, but I cannot mark it as an answer. Again, thanks for your contribution.
Gowtham CpRank #1,552 · 1K reputationPosted Aug 22, 2024, 11:49 AM EDT
1. In C#, a collection is a way to store and manage a group of objects, like a list or an array. It’s a core concept in the C#, helping you organize and work with multiple items.
2. IEnumerable isn’t exactly a collection, it’s more of an interface that allows you to loop through a collection. It lets you access items one by one but doesn’t hold any data itself. So, while
IEnumerablehelps you navigate collections, it’s not a collection in itself.Hope it helps!
Gowtham CpRank #1,552 · 1K reputationPosted Aug 23, 2024, 4:41 AM EDT
Hi Mariusz,
Got it.
In C#, a collection is a class that holds and manages multiple objects. Examples include
List,Dictionary, andQueue. These classes handle storage and offer methods to work with the data they contain.On the other hand,
IEnumerableis an interface that provides a way to iterate over a sequence of elements. It doesn’t manage or store data itself; it’s used by collections to enable looping through items.So, while
IEnumerablehelps with iterating over collections, it’s not a collection itself but a tool for working with collections.Hope that clears things up!
Best,
Gowtham