鉴于我有两个相同类型的c#对象,我想比较它们来创建一个JsonPatchDocument.
我有一个像这样定义的StyleDetail类:
public class StyleDetail
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public decimal OriginalPrice { get; set; }
public decimal Price { get; set; }
public string Notes { get; set; }
public string ImageUrl { get; set; }
public bool Wishlist { get; set; }
public List<string> Attributes { get; set; }
public ColourList Colours { get; set; }
public SizeList Sizes { …
Run Code Online (Sandbox Code Playgroud) 我不明白这里发生了什么......
我有以下错误:
该类型'TestApp.TestVal'
不能用作'T'
泛型类型或方法中的类型参数'TestApp.SomeClass<T>'
.没有来自装箱转换'TestApp.TestVal'
到'System.IComparable<TestApp.TestVal>'
.
以下代码发生此错误:
public enum TestVal
{
First,
Second,
Third
}
public class SomeClass<T>
where T : IComparable<T>
{
public T Stored
{
get
{
return storedval;
}
set
{
storedval = value;
}
}
private T storedval;
}
class Program
{
static void Main(string[] args)
{
//Error is on the next line
SomeClass<TestVal> t = new SomeClass<TestVal>();
}
}
Run Code Online (Sandbox Code Playgroud)
由于枚举是int
默认的并且int实现了IComparable<int>
接口,所以看起来应该没有错误....