2

Nemerle を使用して、ジェネリック型の制約と「必須」の前提条件を持つメソッドを作成したいと考えています。メソッドの戻り値の型に関して、これらの適切な順序/構文は何ですか?

これが私が欲しいもののC#の例です:

//Count the number of items in a 2D array
public static int CountAll<T>(this T[] source)
    where T : Array
{
    Contract.Requires(source != null);
    return source.Sum(sub => sub.Length);
}

これは、コンパイラが気に入らない Nemerle の推測です。

public static CountAll[T](this source : array[T]) : int
    where T : array
    requires source != null
{
    source.Sum(sub => sub.Length);
}

これをコンパイルするにはどうすればよいですか?


編集:

array私が実際に意味したときにキーワードを使用していましたSystem.Array

これはコンパイルされます:

public static CountAll[T](this source : array[T]) : int 
    where T : System.Array
    requires source != null
{
    source.Sum(sub => sub.Length);    
}
4

0 に答える 0