Reputation: 495
I have a code that returns a set of objects. I want to segregate a particular object from that set. I'm trying to use LINQ to do that. But I'm not getting that,
var registerAck = ((pointAck)((response.Item))).Items[0].Item;
var poke = ((pointAck)((response.Item))).Items.Where(x => x.GetType() == typeof(poker));
I'm getting a System.Linq.Enumerable.WhereArrayIterator<> in my poke.
What am I doing wrong here?
Upvotes: 0
Views: 210
Reputation: 4465
.ToList
may or may not be required, because it depends on how you want to use poke
.
For example, if you are going to iterate over the results using foreach
only once, then .ToList
is redundant, and unnecessary code execution and allocations.In short, there may be nothing wrong with your code, depending on how you want to further use poke
.
Where
method.. Checkout .OfType
http://msdn.microsoft.com/en-us/library/vstudio/bb360913(v=vs.100).aspx
It will be slightly more compact and more readable.
Items.OfType<poker>();
Upvotes: 2
Reputation: 495
Sorry. I forgot to add .ToList(). It works.
var poke = ((pointAck)((response.Item))).Items.Where(x => x.GetType() == typeof(poker)).ToList();
Upvotes: 0
Reputation: 54504
Add .ToList()
to convert it to the type of System.Collections.Generic.List<TSource>
var poke = ((pointAck)((response.Item))).Items
.Where(x => x.GetType() == typeof(poker)).ToList();
Upvotes: 3