✅ LINQ, simple query
Is there something I can do to make this query better (faster, more idiomatic, etc)
12 Replies
for a simple in-memory collection i don't think there is a reason for you to use the element selector
you are just taking out a subset of the object, you can just have the groupings contain the objects themselves
you mean the
new {}
part?Well, let's say I want that information
I could use a tuple instead
That way I have a value tuple/struct instead of a class
you can get that information by looking at the
Course
objects instead
they have the information right thereLook at them after the query?
then you don't have to make anything
if
q
is an IGrouping<string, Course>
, then you have all the Course objects from which you can get Title, Number, and TotalHours
you can do IGrouping<string, (string Title, int Number, double TotalHours)>
but those values are trivial to get from the Course object, selecting them out does not really improve the code@reflectronic like this
right
so this is better than `new {} because it doesn't create any new data structures, it just links to existing ones or what?
right, you don't really need to create a new object for each record apparently
thanks