This project is read-only.

Generic Algorithms

using CityLizard.Policy;
...
namespace Algorithms
{
public static class Extension
{
    public static T Sum<P, T>(this P p, params T[] a)
        where P: INumeric<T>
    {
        var r = p._0();
        foreach(var i in a)
        {
            r = p.Add(r, i);
        }
        return r;
    }

    ...
}
}

Usage

using CityLizard.Policy;
using Algorithms;
...
int i = Base.X.Sum(1, 2, 3, 4, 5);
long l = Base.X.Sum(1L, 2, 3, 4, 5);
var s = Base.X.Sum("www", ""); //< compile-time error.

Last edited Feb 7, 2011 at 1:04 PM by sergey_shandar, version 3

Comments

No comments yet.