c# - Is order relevance implied with IEnumerable or should it be explicit? -


For me, IEnumerable & lt; T & gt; C # (Well, .NET) An arbitrary set of data that can be circulated can be supported in any way, such as the result of a SELECT query, a The contents of the array, the character described by the user in the console, or Pi's data data can not be referenced by the index, it is not necessarily finite or infinite, nor can it be modified. It can also be a separate set of data when it is called later, such as IEnumerable & lt; Double & gt; Random numbers It is bits of data such as a consumer being fed like a foreach loop.

Now consider a few more concepts that work with the Data Set: In SQL SQL, the order of the specified rows is not guaranteed and it is not relevant. For example, if you do SELECT * to stack_overflow_posts LIMIT 1 , there is no implication from the database that the line you get back is actually the first line that was inserted, nor For the old line example, you need to explicitly order the results containing the ORDER BY post_date_time .

Is this the same concept in NEF IEnumerable & lt; T & gt; ? Use What is the IEnumerable & lt; T & gt; An implication that will result in always in a certain order? In the earlier examples, I would say, the order would be contained, because if they were described in a different order, the result would be meaningless; If you find the user-typed letters compared to the actual keystrokes in the console, what does it mean to read them? Obviously in LINQ, OrderBy () is, but you want to order to order, but this is a clear ordering, not inherent.

The class implementing the interface effectively prompts to follow a particular pattern, not just implement the methods defined by the interface. Whether IEnumerable & lt; T & gt; Will it mean in a relevant sequence, or is it dependent on the consumers of the calculation so that they can clearly order to do so? If I have a method that produces items in an undefined order - or rather, an order which is not relevant to consumers and is subject to change at any point - I have to be called IEnumerable ?

what IEnumerable & lt; T & gt; An implication that will always result in earnings in a particular order?

No IEnumerable simply guarantees that the object can be repeated, the fact is that the list & lt; T & gt; , for example, always indexes objects in ascending order according to the index list & lt; T & gt; Specifically Blockquote>

A class implementing the interface effectively prompts to follow a particular pattern, not only implement the methods defined by the interface . IEnumerable & lt; T & gt; Does it mean that its data will be found in a relevant sequence, or is it dependent on the consumers of the calculation so that they explicitly order it to do so?

No, implementation IEnumerable does not mean any command while using IEnumerable item, you explicitly provide an order If you want to make sure that your data is exiting in the same sequence every time.

If you think that the CLR storage type that is implementing IEnumerable , this is straightforward. Imagine that you have created a method which is IEnumerable & lt; String & gt; This method list & lt; String & gt; can return, whose implementation IEnumerable does have a fixed order, but it can easily come back to a hashaseet & lt; String & gt; , for which an order is not understood.

If I have a method that produces objects in an undefined order - or rather, an order that is not relevant to consumers and is subject to change at any point - what Me IEnumerable & lt; T & gt; ?

should use something else that says IEnumerable & lt; T & gt; Suits your needs well To be extra clear, you can document your method and tell that the order of the item in the order is undefined and can change from call to call.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -