I have a List of Objects
List<Flywheel> parts1 = new List<Flywheel>();
i want to extract an array of one of the properties.
parts1 = parts.DistinctBy(Flywheel => Flywheel.FW_DMF_or_Solid).OrderBy(Flywheel => Flywheel.FW_DMF_or_Solid).ToList();
string[] mydata = ((IEnumerable)parts1).Cast<Flywheel>()
.Select(x => x.ToString())
.ToArray();
the code for DistinctBy()
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
what i get in my code is a array of string thart each of them is "XXX.Flywheels.Flywheel" but i need to get the actual values.