I have a list of DrawObject[]. Each DrawObject has a Rectangle property. Here is my event:
List<Canvas.DrawObject[]> matrix;
void Control_MouseMove ( object sender, MouseEventArgs e )
{
IEnumerable<Canvas.DrawObject> tile = Enumerable.Range( 0, matrix.Capacity - 1)
.Where(row => Enumerable.Range(0, matrix[row].Length -1)
.Where(column => this[column, row].Rectangle.Contains(e.Location)))
.????;
}
I am not sure exactly what my final select command should be in place of the “????”. Also, I was getting an error: cannot convert IEnumerable<int> to bool.
I’ve read several questions about performing a linq query on a list of arrays, but I can’t quite get what is going wrong with this. Any help?
Edit:
Apologies for not being clear in my intentions with the implementation.
I intend to select the DrawObject that currently contains the mouse location.
It’s not at all clear what you’re trying to do. I suspect you want something like:
… but maybe not. You haven’t shown what you’re trying to do with the result of the query, or what
this[column, row]is there for.You almost certainly don’t want to be using the capacity of the list in the first place – it’s more likely that you’re interested in the
Count, but using the list as anIEnumerable<T>is probably better anyway.EDIT: Okay, so the above query finds all the
drawObjectswhere the rectangle contains the given location. You almost certainly want to use something likeFirst,FirstOrDefault,SingleorSingleOrDefault. For example: