如何继承泛型接口?

belinda_pjm 2008-09-24 02:33:14
public interface IntGenerics<T> where T : abcdefg<T>, ICloneable, IFormattable, IComparable, IComparable<int>, IEnumerable<int> {
T abc( T t1 );
}

这是一个泛型接口...

public class classGenerices{

}
这是我的一个类! 这个类我需要继承 IntGenerices 这个接口 我要怎么去实现接口里面的方法呢? 还有我接口应该带什么样的一个参数呢?
...全文
403 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
NewUser2008 2008-09-24
  • 打赏
  • 举报
回复
classGenerices<T>:IntGenerics<T>
belinda_pjm 2008-09-24
  • 打赏
  • 举报
回复
不过要注意的是你接口他继承了N个类或接口...
那你要继承的类它也要继承N个类或接口... 然后要实现所有的接口和类...
belinda_pjm 2008-09-24
  • 打赏
  • 举报
回复
我自己解决拉哈哈...
public interface IntGenerics <T> where T : IntGenerics <T>, ICloneable, IFormattable, IComparable, IComparable <int>, IEnumerable <int> {
T abc( T t1 );
}

继承后的类..

public class classGenerices:IntGenerics<classGenerices>,ICloneable, IFormattable, IComparable, IComparable <int>, IEnumerable <int>{

#region IntGenerics<classGenerices> 成员

classGenerices IntGenerics<classGenerices>.abc( classGenerices t1 ) {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region ICloneable 成员

object ICloneable.Clone() {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region IFormattable 成员

string IFormattable.ToString( string format, IFormatProvider formatProvider ) {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region IComparable 成员

int IComparable.CompareTo( object obj ) {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region IComparable<int> 成员

int IComparable<int>.CompareTo( int other ) {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region IEnumerable<int> 成员

IEnumerator<int> IEnumerable<int>.GetEnumerator() {
throw new Exception( "The method or operation is not implemented." );
}

#endregion

#region IEnumerable 成员

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
throw new Exception( "The method or operation is not implemented." );
}

#endregion
}

呵呵!
belinda_pjm 2008-09-24
  • 打赏
  • 举报
回复
我在接口中就定义了一个T abc(T t1);
这样一个方法...
现在我要继承这个接口
常规的实现应该就这样就差不多拉 T abc(T t1){ ... } 这样也就查不多拉!

但是泛型他继承接口的话还要带具体的参数..

那么我这里应该要带个什么参数呢?

public class classGenerices:IntGenerics<这个括号里面我应该带个什么参数呢?>{ ... }

更正一下:public interface IntGenerics <T> where T : abcdefg <T>, ICloneable, IFormattable, IComparable, IComparable <int>, IEnumerable <int> {
T abc( T t1 );
}

更正为:public interface IntGenerics <T> where T : IntGenerics <T>, ICloneable, IFormattable, IComparable, IComparable <int>, IEnumerable <int> {
T abc( T t1 );
}
消失的尘芥 2008-09-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 belinda_pjm 的帖子:]
public interface IntGenerics <T> where T : abcdefg <T>, ICloneable, IFormattable, IComparable, IComparable <int>, IEnumerable <int> {
T abc( T t1 );
}

这是一个泛型接口...

public class classGenerices{

}
这是我的一个类! 这个类我需要继承 IntGenerices 这个接口 我要怎么去实现接口里面的方法呢? 还有我接口应该带什么样的一个参数呢?
[/Quote]
怎么去实现接口的方法,你在接口中怎样定义方法,就应该按照你接口里面的规则来实现方法啊!
tao0711 2008-09-24
  • 打赏
  • 举报
回复
给分。。。。。。。。

1。FAN XING

suaigemogu 2008-09-24
  • 打赏
  • 举报
回复
是啊。
suzhu2500084 2008-09-24
  • 打赏
  • 举报
回复
亲爱的牛牛,你的分就给我八,呵呵

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧