根据硬件返回值 查询定义并显示

bobzhang1985 2012-05-10 11:47:59
请问我现在注册motion卡 比如返回 -7 我如何在messagebox.show里显示 ErrorInvalidAdRange ?


public class DASK
{
public const int NoError =0;
public const int ErrorUnknownCardType =-1;
public const int ErrorInvalidCardNumber =-2;
public const int ErrorTooManyCardRegistered =-3;
public const int ErrorCardNotRegistered =-4;
public const int ErrorFuncNotSupport =-5;
public const int ErrorInvalidIoChannel =-6;
public const int ErrorInvalidAdRange =-7;
public const int ErrorContIoNotAllowed =-8;
public const int ErrorDiffRangeNotSupport =-9;
public const int ErrorLastChannelNotZero =-10;
public const int ErrorChannelNotDescending =-11;
}
...全文
78 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
scjypzh 2012-05-10
  • 打赏
  • 举报
回复
使用枚举,不是更简单?
Conmajia 2012-05-10
  • 打赏
  • 举报
回复
反射,Type.GetFields()
bdmh 2012-05-10
  • 打赏
  • 举报
回复
如果非要这样,写一个函数根据数值去返回字符串吧
cheng2005 2012-05-10
  • 打赏
  • 举报
回复
变量名编译之后就不存在了,所以针对变量名的编程都是不现实的。
EnForGrass 2012-05-10
  • 打赏
  • 举报
回复
你可以定义一个Dictionary<int,string>分别存储值和变量名,当获取到值时候,就可以获取对应的变量名
Conmajia 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
引用楼主 的回复:
请问我现在注册motion卡 比如返回 -7 我如何在messagebox.show里显示 ErrorInvalidAdRange ?

C# code

public class DASK
{
public const int NoError =0;
public const int ErrorUnknownCardType ……


DASK 这个文件……
[/Quote]

都给你说了用 Type.GetFields()

看看 MSDN 关于 Type 的这部分吧,这个不用让你重写任何东西。。

bobzhang1985 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
请问我现在注册motion卡 比如返回 -7 我如何在messagebox.show里显示 ErrorInvalidAdRange ?

C# code

public class DASK
{
public const int NoError =0;
public const int ErrorUnknownCardType ……
[/Quote]

DASK 这个文件里有1w多个变量 我不想重新写 ...

111,126

社区成员

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

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

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