LINQ Sum OverflowException?

后端 未结 3 1030
广开言路
广开言路 2021-01-12 07:22

I\'ve implemented a custom IEqualityComparer for EventLogEntry.

public class EventLogEntryListComparison :
    IEqualityComparer         


        
3条回答
  •  一生所求
    2021-01-12 08:08

    LINQ's Enumerable.Sum(...) methods perform the additions inside a checked block. This means that they deliberately throw an exception if the sum overflows.

    Your sum is not inside a checked block, so whether or not it throws an exception depends on... whether it is called from inside a checked block, or a property on the assembly I believe.

提交回复
热议问题