I’m working with an object declared as shown.
DataCollection<Entity> collection = GetDataCollection(...);
Then, I’m picking out two sets of data as below.
IEnumerable<String>
array_1 = collection.Select(
element => element.Attributes["attribute_1"] as String),
array_2 = collection.Select(
element => element.Attributes["attribute_2"] as String);
I’m terribly curious if those two arrays are guaranteed to have the same order. I.e. if their separate orders must be the same as in the original sequence. Or, at the very least, if the order would change for any reason, will the ith element in the first separate list still correspond to the ith element in the other?
They’re not guaranteed to be the same. In reality, you’ll probably notice that the order is typically consistent with the original collection.
If you’re worried about consistency, just add an
OrderByclause to get the order you need (or at least one that is consistent between the two resulting collections).