枚举返回什么值? [英] Enum returns what value?

查看:149
本文介绍了枚举返回什么值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下枚举:

i have the following enum:

public enum Command_ID : uint 
    {
        none = 0x0,
        generic_nack = 0x80000000,
        bind_receiver = 0x00000001,
        bind_receiver_resp = 0x80000001,
        bind_transmitter = 0x00000002,
        bind_transmitter_resp = 0x80000002,
        query_sm = 0x00000003,
        query_sm_resp = 0x80000003,
        submit_sm = 0x00000004,
        submit_sm_resp = 0x80000004,
        deliver_sm = 0x00000005,
        deliver_sm_resp = 0x80000005,
        unbind = 0x00000006,
        unbind_resp = 0x80000006,
        replace_sm = 0x00000007,
        replace_sm_resp = 0x80000007,
        cancel_sm = 0x00000008,
        cancel_sm_resp = 0x80000008,
        bind_transceiver = 0x00000009,
        //bind_transceiver = 9,
        bind_transceiver_resp = 0x80000009,
        outbind = 0x0000000B,
        enquire_link = 0x00000015,
        enquire_link_resp = 0x80000015,
        submit_multi = 0x00000021,
        submit_multi_resp = 0x80000021,
        alert_notification = 0x00000102,
        data_sm = 0x00000103,
        data_sm_resp = 0x80000103,
    }



我正在尝试按如下方式使用枚举:



I am trying to use the enum as follow:

packet.CmdID = PDU.Command_ID.bind_transceiver;



之后,我将其解码为PDU数据包(十六进制格式).请注意,此处提供了所有其他必要的信息,只是未粘贴在此处.

之后,我将整个对象编码为PDU.当我将其发送到SMSC(短消息服务中心)模拟器时,它返回命令ID不正确的错误.

我想知道的是,枚举Command_ID实际上返回了什么值,是"bind_transceiver"吗?如果我使用以下代码



After this, I am decoding this into an PDU packet (Hex format). Please note, all other necessary information is presented, just not pasted here.

After this I am encoding the entire object to an PDU. When I send this to the SMSC (Short Message Service Centre) simulator, it return the error that the command id is incorrect.

what I would like to know is, what value is actually being returned by the enum Command_ID, is it "bind_transceiver"? if I use the following code

uint x = (uint)Enum.Parse(typeof(PDU.Command_ID), Enum.GetName(typeof(PDU.Command_ID), id));



它返回9.如何获取枚举返回0x00000009?

感谢您提前提供任何帮助.



it returns 9. How can I get the Enum to return 0x00000009??

Thanks for any help in advance

推荐答案

请参阅我对问题的评论.他们是一样的.与每个成员关联的枚举成员值是整数类型之一,而不是字符串类型.您观察到的是某些特殊的字符串表示形式,您无需理会.

但是,如果您需要以某种特定格式在某处输出字符串,请学习字符串格式.请参阅:
http://msdn.microsoft.com/en-us/library/system.object. tostring.aspx [^ ];

例如:
http://msdn.microsoft.com/en-us/library/cht2hdff.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/8wch342y.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/d830955a.aspx [ ^ ];

格式为:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx [ ^ ].

首先,您可能需要了解数字类型的工作方式.请看我的文章:
​​枚举类型不枚举!解决.NET和语言限制 [ ^ ].

—SA
Please see my comment to the question. They are the same. Enumeration member values associated with each member are of one of the integer types, not of the string type. What you observe is some particular string representation, which you should not care of.

However, if you need to output strings somewhere in some certain format, learn string formatting. Please see:
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx[^];

for example:
http://msdn.microsoft.com/en-us/library/cht2hdff.aspx[^],
http://msdn.microsoft.com/en-us/library/8wch342y.aspx[^],
http://msdn.microsoft.com/en-us/library/d830955a.aspx[^];

and the formats are:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

First of all, you might need to understand how numeric types work. Please see my article:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^].

—SA


这应该有所帮助:

This should help:

class Program
{
    public enum someEnums
    {
        someEnum = 0x00000009
    }
    static void Main(string[] args)
    {
       string x = string.Format("0X{0:X8}", (int)someEnums.someEnum);
        Console.WriteLine ( x);
        Console.ReadLine();
    }
}


这篇关于枚举返回什么值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆