I have two properties in an object, ChannelName and ChannelValue. I have an Enum with a list of channel Id's.
I want to be able to use a Linq query to say, "select the channel value where the channel name = one of the items in the Enum."
I have this so far, but I get the error:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'string'
The code is:
var channels = Enum.GetNames(typeof(ModbusChannels)).ToList();
var allChannelValues = "";
foreach (var item in channels)
{
allChannelValues = (from x in data where x.ChannelName.Contains(item) select x.ChannelValue);
}
FYI, where 'data' appears in the appears in the query, this is an object that is fully populated.
The Enum has 500 names in it, but here is a shortened version:
public enum ModbusChannels{
M0,
M1,
M2,
M3,
M4,
M5,
M6,
M7,
M8
}
Is this the right way to do this and how do I achieve the query.