I’m learning Linq.
I not sure how I can select data from a generic list.
in the next pseudo-code example, I like to group into a new class by “data”, making a list of “type”, and selecting id (same id for same data)
List<MyClass>
MyClass have:
-------------
string id
string type
string data
example of instances (all of this contained in a List<MyClass>
MyClass1
--------
id = "a"
type = "a"
data = "someData1"
MyClass2
--------
id = "a"
type = "b"
data = "someData1"
MyClass3
--------
id = "b"
type = "c"
data = "someData2"
MyClass4
--------
id = "b"
type = "b"
data = "someData2"
MyClass5
--------
id = "a"
type = "c"
data = "someData1"
I like to obtain something like:
MyNewClassX
id = "a"
types = {"a","b","c"}
data = "someData1"
MyNewClassY
id = "b"
types = {"c","z"}
data = "someData2"
And later… I like to obtain -for example- MyNewclasses where type = “c”
I not sure if is good idea to group to obtain that result or I have to use another Linq query to select the data I want.
1 Answer