Get a great list of identifiers from IEnumerable <T>
I have an IEnumerable that I want to get all the individual MaterialIDs. I have some code that works, but I was wondering if there is a better way to use LINQ. Here is the code I have:
private IEnumerable<int> GetDistinctMaterialIDs(IEnumerable<TankReading> tankReadings) { var distinctMaterialIDs = new List<int>(); foreach (var tankReading in tankReadings) { if (!distinctMaterialIDs.Contains(tankReading.MaterialID)) { distinctMaterialIDs.Add(tankReading.MaterialID); } } return distinctMaterialIDs; } Any help would be appreciated as I learn how LINQ can help me.
+4