小编Spa*_*ose的帖子

如何在枚举中添加.Equals()扩展名?

我目前有以下代码:

public enum FieldType
{
    Int,
    Year,
    String,
    DateTime
}
public enum DataType
{
    Int,
    String,
    DateTime
}
Run Code Online (Sandbox Code Playgroud)

我想为每个方法都有一个扩展方法,这样我就可以这样做:

FieldType fType = FieldType.Year;
DataType dType = DataType.Int;

fType.Equals(dType); //If fType is an Int/Year, and dType is an Int it should return true
dType.Equals(fType); //If dType is an Int, and fType is an Int/Year it should be true
Run Code Online (Sandbox Code Playgroud)

有没有办法创建一个.Equals扩展,这样就可以了?

c#

2
推荐指数
1
解决办法
1763
查看次数

标签 统计

c# ×1