0%

枚举类扩展方法

枚举类

1
2
3
4
5
6
public enum CityEnum
{
北京,
上海,
广州
}

枚举类扩展方法

1
2
3
4
5
6
7
8

public static class EnumCityCodeExt
{
public static bool Is_BJ_北京(this CityEnum enumCityCode)
{
return (int)enumCityCode == 0;
}
}

针对枚举的一些扩展方法,方便调用方,枚举值的判断, 减少输入

调用方演示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Program
{
static void Main(string[] args)
{
var isBJ = CityCode.Is_BJ_北京(); // 此处直接调用扩展方法即可

Console.WriteLine(isBJ); //True
}


public static CityEnum CityCode
{
get
{
return CityEnum.北京;
}
}
}
-------------本文结束感谢您的阅读-------------
本网站所有内容均收集于互联网或自己创作, 方便于网友与自己学习交流,如有侵权,请留言,立即处理

欢迎关注我的其它发布渠道

本文标题:枚举类扩展方法

文章作者:peter

发布时间:2020年03月02日 - 14:03

最后更新:2022年07月28日 - 11:07

原始链接:https://www.123zhibei.xyz/article/7d64b876.html

许可协议: 转载请保留原文链接及作者。