Answers for "linq get objects of specific type in list"

C#
0

linq get objects of specific type in list

// LINQ selection by type of an object

Class Base{}
Class A : Base {}
Class B : Base {}

List<Base> collection = new List<Base>();
collection.Add(new A());
collection.Add(new B());
collection.Add(new A());
collection.Add(new A());
collection.Add(new B());

var ofTypeA = collection.OfType<A>();
Posted by: Guest on November-18-2020

Code answers related to "linq get objects of specific type in list"

C# Answers by Framework

Browse Popular Code Answers by Language