I have a Dictionary<string, DemoRecord>
with DemoRecord
having a field Size
.
I now want to calculate the sum of all sizes using LINQ. Here’s the example
public record DemoRecord(string Name, ulong Size);
public class DemoStackOverflow()
{
public ulong GetSum(Dictionary<string, DemoRecord> data)
{
return data.Sum(x => x.Value.Size); // Syntax error
}
}
However, Visual Studio highlights the Sum
method with an error message for which I cannot comprehend the problem.
When explicitly specifying the generic type, it just highlights the data
variable with another error message.
Is this impossible? It really seems like a trivial LINQ method. Visual Studio itself suggest that Sum
exists on the Dictionary
.