IEnumerable 🆚 IEnumerator Interfaces in C#

preview_player
Показать описание

Today's Advanced C# Topic is: IEnumerable and IEnumerator Interfaces

In this video you will learn what IEnumerable and IEnumerator are
What are advantages of IEnumerable and IEnumerator
When to use them
How to use them
What are advantages of using IEnumerable and IEnumerato
How IEnumerator and IEnumerable are related to lists, arrays, and other types of colletions.

The IEnumerable interface is the base Interface for many collections in C#, and its job is to provide a way of iteration through a collection. That is why we can use foreach loops to go through a List or a Dictionary. In simple English when a collection class implements the IEnumerable interface it becomes countable, and we can count each element in it individually

There are 2 versions of the IEnumerable Interface

1.IEnumerable for generic collections
2.IEnumerable for non generic collections

But since generic collections were introduced later after the non-generic ones and it is no longer recommended to use the non-generic collections in a new project due to their need to perform boxing and unboxing (converting the types of objects), we will explain how to use the IEnumerable T interface in this lesson

when it is recommended to use the IEnumerable interface:

- Your collection represents a massive database table, you don’t want to copy the entire thing into memory and cause performance issues in your application.

When it is not recommended to use the IEnumerable interface:

- You need the results right away and are possibly mutating / editing the objects later on. In this case, it is better to use an Array or a List

ienumerable vs ienumerator C#
implementing ienumerable and ienumerator
use of ienumerable and ienumerator in c#
ienumerator in c example
ienumerable vs ienumerablet
why we use ienumerable in c
ienumerable vs enumerable c
ienumerator in c# geeksforgeeks

interface in c# with example code project
tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Рекомендации по теме
Комментарии
Автор


Here is an article about IEnumerable and IEnumerator Interfaces with a complete code, enjoy!

tutorialsEU
Автор

Super clear explanation - exactly what I needed!

gazells
Автор

This is some top tier explanation, I have no choice but to subscribe :)

lowkeyhuman
Автор

Best explanation on YouTube. Thank you!

dayday
Автор

Good video. Question: how relevant is it to learn how to implement IEnumerator<T> ? Should it be an urgent matter for post-beginner students/juniors or shouldn't one be bothered with it for now?

angel_machariel
Автор

Wow that was brilliant. I finally understand what IEnumerable does. I didn't know what a queue was, so I watched your video on that, which was also great. So well explained and really helpful. You are definitely my new go to source for C#. Thanks again. Simon

simonroyjonesuk
Автор

Great job at conveying the principles!

bryanburger
Автор

Thank you so much for this video. Well explained and I received so much value

FumeCreates
Автор

top top top, thanks, you are the best c# teacher .

juniorlucival
Автор

Thanks, a lot. This video helps me a lot.

oaksoeaung
Автор

amazing video, now i understood what this mean, this video also helped me to see the importance of interfaces in general, not only IEnumerable interface.

carlossantamaria
Автор

The first ”ahaa” moment I’ve had regarding interfaces, when you described the issues presented without interfaces. So they provide similar functionality among othervise unrelated classes. For example 😁

BackeB
Автор

Well. I got the examples but I didn't get the main idea why do we need this "IEnumerable" thing? To treat List<int> and int array with the same function? At the end they both are <int> so we can collect List<int> values to array first and just make a function to work only with arrays. Or array to list. Because they both are <int>. So why do we need all of this?

andrewfedorov
Автор

so just a logical question:
Why don't we just make dogs a public list and itterate in the foreach loop through shelter.dogs?

andreashecht
Автор

Great video, why can't I save it?

nikolazagorac
Автор

Thank you ... you didn't cover anything necessary about it ... Very elementary ... but It helpful yet

oblivion
Автор

So we use IEnumerable, when we want introduce class like array or list. Yes?

hgswtju
Автор

Can we consider this as runtime polymorphism, because the IEnumerable interface is holding different array types at runtime?

Thank you.

danielbereketsiyum
Автор

Instead of going, foreach loop shelter, couldnt we just loop though => shelter.dogs in the foreach looop since its public list?

TheKrckeR
Автор

Good video but can you explain why it is necessary to have 2 interfaces Ienumerable and Ienumerator ? What is the need for Ienumerable when it is Ienumerator that does all the work ?

youtischia