EN IYI TARAFı C# READONLYCOLLECTIONBASE KULLANıMı

En iyi Tarafı C# ReadOnlyCollectionBase Kullanımı

En iyi Tarafı C# ReadOnlyCollectionBase Kullanımı

Blog Article

This class makes the underlying collection available through the InnerList property, which is intended for use only by classes that are derived directly from ReadOnlyCollectionBase. The derived class must ensure that its own users cannot modify the underlying collection.

akuaku 123k3333 gold badges174174 silver badges203203 bronze badges Add a comment  

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

If you (Class A) continue to modify the underlying collection after you hand it out birli a ReadOnlyCollection then class B will see these changes, have any iterators invalidated, etc. and generally be open to any of the usual concurrency issues with collections.

Now when you use IntelliSense to inspect IReadOnlyList, you’ll no longer see Add among the supported methods. Figure 2 below displays the members of the IReadOnlyList instance.

Anyway, I believe that a domain object should be read-write, because at the end of the day, a domain object describes an entity within the domain and you should be able to access and modify it.

1. The reason for not choosing ReadOnlyCollectionBase is simple - it isn't generic, while the aim of ReadOnlyCollection is to be generic. Thus it needs a much different inheritance tree.

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

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are derece guaranteed to be thread safe.

A ReadOnlyCollectionBase instance is always read-only. See CollectionBase for a modifiable version of this class.

Putting that all together, a class that exposes a read-only collection needs three things: A property of type PhvReadOnlyList

Inheriting from a non-generic base class would be ineffecient. If the type was using a non-generic base, all it would be would be a thin layer C# ReadOnlyCollectionBase Nedir above the base collection, where the generic features would simply derive from casting from the underlying object instances of the base collection.

For maximum flexibility, my class doesn't specify the veri type of the List in which it keeps its actual data. Instead, I declare my UnderlyingList variable to use any class that implements the IList C# ReadOnlyCollectionBase Nasıl Kullanılır interface. I've also made this a generic class: Rather than specify what kind of List I'm working with, I've forced my class to be instantiated with a veri type that the code refers to as T. Wherever C# ReadOnlyCollectionBase Nedir in my code I need to specify my List's veri type, I just use the T reference. Finally, I've chosen to have this class implement the generic version of IEnumerable, which requires two versions of the C# ReadOnlyCollectionBase Nasıl Kullanılır GetEnumerator method -- but the code is identical C# ReadOnlyCollectionBase Temel Özellikleri in both versions of the method. Listing 1. The basics of the PhvReadOnlyList class.

If however your intent is to prevent the calling code from observing updates from other threads you'll have to fall back to solutions already mentioned, to perform a deep or shallow copy depending on your need.

Report this page