0

私はそのようなコードを持っています:

using System.Collections.Generic;
using System.Linq;

namespace PricingCoefficientService.Extensions
{
    public static class IntExt
    {
        public static bool IsIn(this int integer, IEnumerable<int> collectionOfIntegers)
        {
            return collectionOfIntegers.Contains(integer);
        }
    }
}

intを拡張した拡張メソッドです。その機能は明らかだと思います。

しかし、値の型やオブジェクトごとに使用できるようにするためにジェネリックにしたくない場合はどうすればよいでしょうか?

何か案が?

ありがとうございました

4

3 に答える 3

1

値型のみが必要な場合

public static bool IsIn(this ValueType integer, IEnumerable<int> collectionOfIntegers)
{
....
}
于 2013-09-19T09:23:23.503 に答える