Given a List<ComplexObject>, how can I create a new list of named tuples? So for every ComplexObject in the original list, create a new tuple with certain values from the ComplexObject?
public class ComplexObject
{
public string SomeString { get; set; }
public int SomeInt { get; set; }
public bool SomeBool { get; set; }
// More properties that are irrelevant for the purpose of this question...
}
This is what I'm trying:
List<ComplexObject> complexObjects = new List<ComplexObject>
{
new ComplexObject { SomeString = "SomeString01", SomeInt = 1, SomeBool = true },
new ComplexObject { SomeString = "SomeString02", SomeInt = 2, SomeBool = false },
new ComplexObject { SomeString = "SomeString03", SomeInt = 3, SomeBool = true },
};
List<(string SomeString, int SomeInt, bool SomeBool)> complexTuples
= complexObjects.SelectMany(obj => (obj.SomeString, obj.SomeInt, obj.SomeBool));
However this results in an error:
The type arguments for method 'Enumerable.SelectMany(IEnumerable, Func>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.