ExtensionMethod.NET Home of 844 C#, Visual Basic, F# and Javascript extension methods

FastSum

Sum decimals

Source

public static decimal FastSum<T>(this IEnumerable<T> source, Func<T, decimal> selector)
{
    //if (source == null)
    //    throw new ArgumentNullException("source");
    //if (selector == null)
    //    throw new ArgumentNullException("selector");

    decimal num = 0;

    foreach (T item in source)
    {
        if (item != null)
        {
            num += selector(item);
        }
    }

    return num;
}

Example

if (sqlAL.Any()) value36 = sqlAL.FastSum(w => (decimal)w.TH013S);

Author: unknow

Submitted on: 15 dec 2020

Language: csharp

Type: IEnumerable<T>

Views: 569