I have a code:
var status = ...
var StatusMapping = new Dictionary<AnotherStatus, IList<Status>>
{
{
AnotherStatus,
new List<Status>
{
Status1,
Status2
}
}
}
foreach (var keyValuePair in StatusMapping)
{
if (keyValuePair.Value.Contains(status))
{
return keyValuePair.Key;
}
}
throw Exception();
I'm new to C#, switched from Java. In java it is easily done like this:
return StatusMapping
.entrySet()
.stream()
.filter(e -> e.getValue().contains(status))
.map(Map.Entry::getKey)
.findFirst()
.orElseThrow(() -> new Exception());
Is there a way to do it with LINQ?