5 Basit Teknikleri için C# IEnumerable Nerelerde Kullanılıyor

Wiki Article

[Edit] - Needless to say - it's not "either this or that". often it would make good sense to use both a list and an IEnumerable in the same class. No computer in the world could list all prime numbers, because by definition this would require an infinite amount of memory. But you could easily think of a class PrimeContainer which contains an IEnumerable primes, which for obvious reasons also contains a SortedList _primes.

Örneğin oluşturduğumuz bir List içerisine tığ Add komutu ile ekleme yapabiliyoruz yahut Count ile içerisinde bulunan elemanların sayısını alabiliyoruz ve bunu foreach içinde kullanabiliyoruz. Peki List bir sınıf olmasına rağmen foreach nasıl buna mezuniyet veriyor?

Şu anda etkili olarak web ve hareketli projeler vüruttiriyorum ve 2013 yılından beri makale dolak ile müşterek YouTube ve Udemy platformlarında video derunerik üretiyorum.

Analogy: Imagine you are a detective on an aeroplane . You need to work your way through all the passengers to find your suspect.

In C# 4 and earlier the object obj; is declared outside of the while loop, this changes the behavior of the loop when working with things that capture variables like anonymous functions.

So if you working with only in-memory veri collection IEnumerable is a good choice but if you want to query data collection which is connected with database `IQueryable is a better choice kakım it reduces network traffic and uses the power of SQL language.

This is a birçok video on youtube C# IEnumerable Nerelerde Kullanılıyor which demonstrates how these interfaces differ , worth a watch. Below goes a long descriptive answer for it.

It has a good performance when you are iterating through big objects or collections because it does not load the entire object to memory in order to make iteration.

Where the execution of a query is going to be performed "in process", typically all that's required is the C# IEnumerable Nasıl Kullanılır code (kakım code) to execute each part of the query.

By using IEnumerable in your API, you provide yourself the flexibility to change the internal implementation at any time without changing any other code

This kişi be very C# IEnumerable Kullanımı useful in certain circumstances, for instance in a massive database table you don't want to copy the entire thing into memory before you start processing the rows.

Generally, don't C# IEnumerable Nerelerde Kullanılıyor worry about what's actually in the IEnumerables, bey it will be completely different from your actual code. C# IEnumerable Nedir Only worry about the actual output when you iterate over it :)

Reed CopseyReed Copsey 561k7979 gold badges1.2k1.2k silver badges1.4k1.4k bronze badges 3 2 I agree strongly with your point about decoupling from the implementation, but I also think there's a point for making clear the expected usage; even if I have a List, referring to it kakım IEnumerable makes it clear that the functionality I'm expecting from the collection in that usage is the enumerability functionality, and derece any of the other List functionality.

The first method advances to the next object in the IEnumerable object that created the enumerator, returning false if it's done, and the second returns the current object.

Report this wiki page