Enumartion标志 [英] Enumartion flags

查看:71
本文介绍了Enumartion标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

谁能给我一个链接,我可以找到一个如何制作

enumaration标志的教程?不是结构(公共枚举MyFlags {...})但是如何使用
作为成员值(0x01,0x02)等...


谢谢。

何塞。

Hello,
Can anyone give me a link where I can find a tutorial on how to make
enumaration flags? Not the structure (public enum MyFlags{...}) but how to
asign the members values (0x01, 0x02) etc...

Thanks.
Jose.

推荐答案

何塞,


如果你要去要使用标志值,那么你必须确保

值为零且权力为2.因此,你的值将是:


0

1

2

4

8

16

32

64

128






现在用十六进制值表示这些时,你会注意到这一点:


0x0001

0x0002

0x0004

0x0008

0x0010

0x0020

0x0040

0x0080

0x0100

0x0200


希望这会有所帮助。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspersh ouse.com


" Jose Ines" <乔************ @ msn.com>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP10.phx.gbl ...
Jose,

If you are going to use flag values, then you have to make sure that the
values are zero and the powers of 2. So, your values would be:

0
1
2
4
8
16
32
64
128
etc
etc

Now when representing these with hex values, you will notice this:

0x0001
0x0002
0x0004
0x0008
0x0010
0x0020
0x0040
0x0080
0x0100
0x0200

Hope this helps.

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

"Jose Ines" <jo************@msn.com> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
你好,任何人都可以给我一个链接,我可以找到如何制作
enumaration标志的教程吗?不是结构(public enum MyFlags {...}),而是如何
作为成员值(0x01,0x02)等...

谢谢。
何塞。
Hello,
Can anyone give me a link where I can find a tutorial on how to make
enumaration flags? Not the structure (public enum MyFlags{...}) but how to
asign the members values (0x01, 0x02) etc...

Thanks.
Jose.



嗨Jose,


[Flags]

enum MyFlags

{

首先= 0x01,

秒= 0x02,

第三= 0x04

}


[标志]属性不是必需的,但它改变了方式ToString()方法

的工作原理。


HTH

B \ rgds




" Jose Ines" <乔************ @ msn.com>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP10.phx.gbl ...
Hi Jose,

[Flags]
enum MyFlags
{
First = 0x01,
Second = 0x02,
Third = 0x04
}

[Flags] attribute is not necessary but it changes the way ToString() method
works.

HTH
B\rgds
100

"Jose Ines" <jo************@msn.com> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
你好,任何人都可以给我一个链接,我可以找到如何制作
enumaration标志的教程吗?不是结构(public enum MyFlags {...}),而是如何
作为成员值(0x01,0x02)等...

谢谢。
何塞。
Hello,
Can anyone give me a link where I can find a tutorial on how to make
enumaration flags? Not the structure (public enum MyFlags{...}) but how to
asign the members values (0x01, 0x02) etc...

Thanks.
Jose.



嗨尼古拉斯,


旗帜不一定是2的力量。


B \ rgds




Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:eQ ************** @ tk2msftngp13.phx.gbl ...
Hi Nicholas,

Flags doesn''t have to be power of 2.

B\rgds
100

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eQ**************@tk2msftngp13.phx.gbl...
何塞,
如果你打算使用标志值,那么你必须确保
值为零且2的幂。所以,你的值将是:

0
1
2
8
16
64
128

等等

现在用十六进制值表示这些时,你会注意到这一点:

0x0001
0x0002
0x0004
0x0008
0x0010
0x0020
0x0040
0x0080
0x0100
0x0200
希望这会有所帮助。

-
- mv*@spam.guard.caspershouse.com

Jose Ines <乔************ @ msn.com>在消息中写道
新闻:O4 ************** @ TK2MSFTNGP10.phx.gbl ...
Jose,

If you are going to use flag values, then you have to make sure that the values are zero and the powers of 2. So, your values would be:

0
1
2
4
8
16
32
64
128
etc
etc

Now when representing these with hex values, you will notice this:

0x0001
0x0002
0x0004
0x0008
0x0010
0x0020
0x0040
0x0080
0x0100
0x0200

Hope this helps.

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

"Jose Ines" <jo************@msn.com> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
你好,
任何人都可以给我链接,我可以找到如何制作
enumaration标志的教程?不是结构(public enum MyFlags {...}),而是如何
来指定成员值(0x01,0x02)等......

谢谢。
Jose。
Hello,
Can anyone give me a link where I can find a tutorial on how to make
enumaration flags? Not the structure (public enum MyFlags{...}) but how to asign the members values (0x01, 0x02) etc...

Thanks.
Jose.




这篇关于Enumartion标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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