声明一个方法,使其参数为泛型类

时间:2012-08-19 02:18:02

标签: c# generics

我有一个如下定义的界面:

public interface IOwlAnnotationTuple<T1, T2, T3>

然后也是这样的类:

public class OwlAnnotationTuple : IOwlAnnotationTuple<string, OWLClass, string>

然后我有一个anther接口,我正在为它添加一个方法,我希望它采用我在上面定义的这个接口的参数,所以我这样定义它但是我得到错误“&gt;是预期的。” / p>

void AddAnnotation(IOwlAnnotationTuple <string annotationName, OWLClass owlClass, string annotationValue>);

那么声明它的正确语法是什么?

1 个答案:

答案 0 :(得分:3)

您试图命名三个参数,但如果您只需要一个参数,则只列出一个参数:

void AddAnnotation(IOwlAnnotationTuple<string, OWLClass, string> owlAnnotationTuple);

void AddAnnotation(OwlAnnotationTuple owlAnnotationTuple);

owlAnnotationTuple的类型为IOwlAnnotationTuple<string, OWLClass, string>。类型string / OWLClass没有单独的参数,因此您无法为其命名。