lex*_*eme 2 c# generics interface
所以这是我的问题:
我有界面:
public interface ICell<Feature>
where Feature: struct, IComparable<ICell<Feature>>
{
List<ICell<Feature>> Window { get; set; }
Feature GenusFeature { get; set; }
Double VitalityRatio { get; set; }
String PopulationMarker { get; set; }
Boolean Captured { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并希望以ISubstratum这种方式实现接口:
public interface ISubstratum<K,T> : IDisposable
where K : IDisposable
where T : struct
{
ICell<T> this[Int32 i, Int32 j] { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但编译器说:
The type 'T' cannot be used as type parameter 'Feature' in the generic type or method 'Colorizer.Core.ICell<Feature>'. There is no boxing conversion or type parameter conversion from 'T' to 'System.IComparable<Colorizer.Core.ICell<T>>'.
在一些可能的ISubstratum实现中,我计划将位图作为K && ICell(扩展像素信息)传递为T.
怎么解决这个?
谢谢!
基本上你必须对T有一个额外的约束:
where T : struct, IComparable<ICell<T>>
Run Code Online (Sandbox Code Playgroud)
那它应该工作正常.这是需要满足在相同的约束Feature在ICell<Feature>.
我也建议你重命名类型参数Feature,以TFeature使其更明显的类型参数.
| 归档时间: |
|
| 查看次数: |
1778 次 |
| 最近记录: |