1/8/2024 0 Comments Icollections app![]() ![]() interface does not have these methods and properties that interface has, because it does not make any sense that will have these methods and properties that interface has. The property Count of interface supposes to return this number. This explains why interface has the "Add" and "Remove" methods.īecause that instances of interface are finite collections then the word "finite" implies that every collection of this interface always has a finite number of items and elements in it. interface represents a finite dynamic collection that are changeable, which means that exist items can be removed from the collection and new items can be added to the same collection. This is all reasonable, rational, logical and makes sense that interface inherits from interface, because theoretically every collection is also both enumerable and iterable and this is theoretically possible to go over all the items and elements in every collection. , is more informative because this generic interface explicitly states what is the type of the things in the collection. The generic version of this interface, i.e. When the class of some instance implements the interface then, in simple words, we can say that this instance is some collection of things. Instances of interface behaves very similar to C++ iterators. This means that this is also possible to enumerate all the items and elements that this instance contains.Įvery class that implements the interface also implements the GetEnumerator method that takes no arguments and returns an instance. When the class of some instance implements the interface then, in simple words, we can say that this instance is both enumerable and iterable, which means that this instance allows somehow in a single loop to go/get/pass/traverse/iterate over/through all the items and elements that this instance contains. ![]() Lets try thinking outside of the box with/by logic and understand clearly these three interfaces in your question: IEnumration Contains only GetEnumerator method to get Enumerator and make a loopingĬonsole.WriteLine("Name:", p.Name, p.Age) You don't have the liberty to do the same with IEnumerable. With ICollection you can modify the collection by using the methods like add/remove.ICollection is inherited from IEnumerable.ICollection contains additional methods: Add, Remove, Contains, Count, CopyTo.IEnumerable - contains only GetEnumerator method to get Enumerator and allows looping.There are some basics difference between ICollection and IEnumerable More information on Defining and Managing Relationships MSDN Requirements for Creating POCO Proxies MSDN In order for the dynamic proxy to be created as a navigation property, the virtual type must implement ICollection.Ī navigation property that represents the "many" end of a relationship must return a type that implements ICollection, where T is the type of the object at the other end of the relationship. By default, navigation properties in Entity Framework come with change tracking and are proxies. In general - IEnumerable (MSDN: ) for a list of objects that only needs to be iterated through, ICollection (MSDN: ) for a list of objects that needs to be iterated through and modified, List for a list of objects that needs to be iterated through, modified, sorted, etc (See here for a full list: ).įrom a more specific standpoint, lazy loading comes in to play with choosing the type. Usually what you choose will depend on which methods you need access to.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |