cast IDictionary键类型(.NET 2.0) [英] cast IDictionary key type (.NET 2.0)

查看:50
本文介绍了cast IDictionary键类型(.NET 2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个OrderedDictionary对象,其中键是枚举。是否有一个

简单的方法将它转换为整数?示例/文件赞赏。


谢谢

Andrew

Hi

I have an OrderedDictionary object where the key is an enum. Is there an
easy way to cast it to an integer? Examples/document appreciated.

Thanks
Andrew

推荐答案

Andrew,


如果键作为对象返回给你,那么你必须首先将它转换为枚举类型,然后是int,如下所示:


对象键= ...;

int keyInt =(int)(EnumType)键;


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

" J055" < j0 ** @ newsgroups.nospamwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...
Andrew,

If the key is returned to you as an object, then you have to cast it to
the enum type first, then an int, like so:

object key = ...;
int keyInt = (int) (EnumType) key;

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"J055" <j0**@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...




我有一个OrderedDictionary对象,其中键是枚举。是否有一个

简单的方法将它转换为整数?示例/文件表示赞赏。


谢谢

Andrew
Hi

I have an OrderedDictionary object where the key is an enum. Is there an
easy way to cast it to an integer? Examples/document appreciated.

Thanks
Andrew



只是好奇,你怎么不能直接去一个int?


谢谢。


-

Saad Rehmani / Prodika / Dallas / TX / USA
Just curious, How come you cant go directly to an int?

Thanks.

--
Saad Rehmani / Prodika / Dallas / TX / USA

Andrew,


如果将密钥作为对象返回给您,然后你必须首先将

转换为枚举类型,然后转换为int,如下所示:


object key = ...;

int keyInt =(int)(EnumType)key;

希望这会有所帮助。


" J055" < j0 ** @ newsgroups.nospamwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...
Andrew,

If the key is returned to you as an object, then you have to cast
it to the enum type first, then an int, like so:

object key = ...;
int keyInt = (int) (EnumType) key;
Hope this helps.

"J055" <j0**@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

>嗨

我有一个OrderedDictionary对象,其中键是枚举。是否有一种简单的方法可以将其转换为整数?示例/文档表示赞赏。

谢谢
Andrew
>Hi

I have an OrderedDictionary object where the key is an enum. Is there
an easy way to cast it to an integer? Examples/document appreciated.

Thanks
Andrew



Saad,


因为当您取消装箱值类型时,您必须先取消装入正确的

类型。它不是一个强制转换操作(虽然语法相同)。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" ; Saad Rehmani < sa ********** @ gmail.comwrote in message

news:44 ******************** ******@msnews.microsoft .com ...
Saad,

Because when you unbox a value type, you have to unbox to the correct
type first. It''s not a casting operation (although the syntax is the same).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Saad Rehmani" <sa**********@gmail.comwrote in message
news:44**************************@msnews.microsoft .com...

好​​奇,你怎么不能直接去一个int?

谢谢。


-

Saad Rehmani / Prodika / Dallas / TX / USA
Just curious, How come you cant go directly to an int?
Thanks.

--
Saad Rehmani / Prodika / Dallas / TX / USA

> Andrew,

如果键作为对象返回给你,那么你必须首先将它转换为枚举类型,然后转换为int,如下所示:

对象键= ...;
int keyInt =(int)(EnumType)键;
希望这会有所帮助。

" J055" < j0 ** @ newsgroups.nospamwrote in message
新闻:%2 **************** @ TK2MSFTNGP06.phx.gbl ...
>Andrew,

If the key is returned to you as an object, then you have to cast
it to the enum type first, then an int, like so:

object key = ...;
int keyInt = (int) (EnumType) key;
Hope this helps.

"J055" <j0**@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

>>嗨

我有一个OrderedDictionary对象,其中键是枚举。是否有一种简单的方法可以将其转换为整数?示例/文件表示赞赏。

谢谢
Andrew
>>Hi

I have an OrderedDictionary object where the key is an enum. Is there
an easy way to cast it to an integer? Examples/document appreciated.

Thanks
Andrew



这篇关于cast IDictionary键类型(.NET 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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