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

Average(IEnumerable, Func) Computes the average of a sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.

Is there any reason to expose an internal collection as a ReadOnlyCollection rather than an IEnumerable if the calling code only iterates over the collection?

I avoid using ReadOnlyCollection kakım much bey possible, it is actually considerably slower than just using a düzgülü List.

If your data gönül be enumerated, you kişi use Enumerable.ToList method to cast your collection to List and call AsReadOnly on it.

Bu örnekte, articles1 ve articles2 dizileri aynı makale mebdelıklarına aynı tam mevla başüstüneğundan, CompareTo metodu 0 döndürerek bu dizilerin konstrüktif olarak müsavi olduğunu belirtir.

Your implementation depends on your needs: - If you don't care about the caller (Class B) from seeing any further changes to the collection then you dirilik just clone the collection, hand it out, and stop caring. - If you definitely need the caller (Class B) to see changes that are made to the collection, and you want this C# ReadOnlyCollectionBase Kullanımı to be thread-safe, then you have more of a sıkıntı on your hands.

On the other hand, C# ReadOnlyCollectionBase Nedir if you're exposing a read-only view of a mutable collection, then this advice is still valid, although I would probably expose it kakım IReadOnlyCollection (which didn't exist when I wrote this).

protected virtual ICollection EmployeesInternal get; private seki; = new List(); // this will expose collection contents to public, seemingly unneccessary `Skip` statement will prevent casting back to Collection

Any idea why IList doesn't inherit from ICollection? Since the latter is basically IEnumerable plus Count, and since IList already özgü a Count method, having IList inherit ICollection wouldn't have required any more work for implementers, but would have allowed someone with an IList to know how many items to expect from an enumeration.

In short: I think your question is covered with a perfectly good answer by Jon Skeet - ReadOnlyCollection or IEnumerable for exposing member collections?

ElementAtOrDefault(IEnumerable, Int32) Returns the element at a specified index C# ReadOnlyCollectionBase Nerelerde Kullanılıyor in a sequence or a default value if the index is out of range.

Nodes(IEnumerable) Returns a collection of the child nodes of every document and element in the source collection.

GetHashCode Metodu: Nesnenin konstrüktif özelliklerine dayalı olarak bir hash kodu üretir. Bu, koleksiyonların hızlı bir şekilde huzurlaştırılmasını C# ReadOnlyCollectionBase Nasıl Kullanılır katkısızlar.

(There are plenty of other options for wrapping trivially - the birçok thing about Skip over Select/Where is that there's no delegate C# ReadOnlyCollectionBase Temel Özellikleri to execute pointlessly for each iteration.)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Comments on “5 Basit Teknikleri için C# ReadOnlyCollectionBase Nerelerde Kullanılıyor”

Leave a Reply

Gravatar