为什么迭代枚举返回重复键?(Why Iterating through the enum return duplicate keys?)
我现在正在处理有关注册表的一些事情。
我检查了
System.Security.AccessControl
的枚举RegistryRights
。public enum RegistryRights { QueryValues = 1, SetValue = 2, CreateSubKey = 4, EnumerateSubKeys = 8, Notify = 16, CreateLink = 32, Delete = 65536, ReadPermissions = 131072, WriteKey = 131078, ExecuteKey = 131097, ReadKey = 131097, ChangePermissions = 262144, TakeOwnership = 524288, FullControl = 983103, }
这个枚举是一个按位,我知道枚举可以包含重复的值。 我试图通过这段代码迭代枚举:
foreach (System.Security.AccessControl.RegistryRights regItem in Enum.GetValues(typeof(System.Security.AccessControl.RegistryRights))) { System.Diagnostics.Debug.WriteLine(regItem.ToString() + " " + ((int)regItem).ToString()); }
还有Enum.GetName(typeof(RegistryRights),regItem)返回相同的键名。
我得到的输出是:
QueryValues 1 SetValue 2 CreateSubKey 4 EnumerateSubKeys 8 Notify 16 CreateLink 32 Delete 65536 ReadPermissions 131072 WriteKey 131078 ReadKey 131097 ReadKey 131097 ChangePermissions 262144 TakeOwnership 524288 FullControl 983103
有人可以告诉我为什么我会得到重复的键?(“ReadKey”而不是“ExecuteKey”) 如何强制它将int转换为值的第二个键? 为什么ToString不返回真正的键值?
I am working now on some stuff regarding registry.
I checked the enum
RegistryRights
inSystem.Security.AccessControl
.public enum RegistryRights { QueryValues = 1, SetValue = 2, CreateSubKey = 4, EnumerateSubKeys = 8, Notify = 16, CreateLink = 32, Delete = 65536, ReadPermissions = 131072, WriteKey = 131078, ExecuteKey = 131097, ReadKey = 131097, ChangePermissions = 262144, TakeOwnership = 524288, FullControl = 983103, }
This enum is a bitwise,And I know that enums can contains duplicate values. I was trying to iterate through the enum by this code:
foreach (System.Security.AccessControl.RegistryRights regItem in Enum.GetValues(typeof(System.Security.AccessControl.RegistryRights))) { System.Diagnostics.Debug.WriteLine(regItem.ToString() + " " + ((int)regItem).ToString()); }
also Enum.GetName(typeof(RegistryRights),regItem) return the same key name.
and the output I got is:
QueryValues 1 SetValue 2 CreateSubKey 4 EnumerateSubKeys 8 Notify 16 CreateLink 32 Delete 65536 ReadPermissions 131072 WriteKey 131078 ReadKey 131097 ReadKey 131097 ChangePermissions 262144 TakeOwnership 524288 FullControl 983103
Can someone please tell me why do I get duplicate keys?("ReadKey" instead of "ExecuteKey") How can I force it to cast the int to the second key of the value ? and why ToString does not return the real key value?
原文:https://stackoverflow.com/questions/18558574
最满意答案
检查以下代码:
var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor; var ns:Namespace = appXml.namespace(); trace(appXml.ns::version);
Check the following code:
var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor; var ns:Namespace = appXml.namespace(); trace(appXml.ns::version);
相关问答
更多-
程序在epoll_wait()调用中无限期等待。 这可能是由于使用了EPOLLET 。 参见man epoll , Level-triggered和edge-triggered : 调用者可能最终等待输入缓冲区中已存在的某些数据。 只是用 rwEpollEvent.events = EPOLLIN; 代替。 Program is infinitely waiting at epoll_wait() call. This is possibly due to using EPOLLET. See m ...
-
Flash CS将根据“AIR设置”窗口中复选框的顺序重写列表。 更改Descriptor.3.x.xsd文件中配置文件的顺序无济于事。 您可以将app.xml文件设置为只读,只要您不必进行任何其他更改即可。 不太好的解决方案...... Flash CS is rewriting the list based on the order of the checkboxes in the AIR Settings window. Changing the order of the profiles in th ...
-
我假设你说在关闭套接字后你的应用程序可以继续合理地继续运行吗? 看起来更好的方法是获得一个中介线程,通知来自任何工作线程的套接字关闭请求,通知其他线程该套接字现在已经死了,并负责关闭套接字本身。 这消除了对失败原因的担忧,因为它全部在单个线程中处理。 I assume you're saying it's possible for your application to reasonably continue after shutting down the socket? It seems that a b ...
-
EOF返回0(属于if ... <= 0),但不设置errno,它可能包含过时的代码。 尝试单独测试0和负(错误,-1)值。 关于“strace”:我在家中以及之前的工作中使用过它。 不幸的是,它没有安装在我目前的工作环境中。 当它可用时,它是一个有用的工具。 在这里,我和提问者一起拿着“让我们阅读精细的手册”(man read)方法:-) EOF returns 0 (falls into if ... <= 0), but does not set errno, which may have an ou ...
-
从InputStream读取时SocketException错误的文件描述符(SocketException bad file descriptor when reading from InputStream)[2024-04-30]
根据 Socket#getOutputStream类的文档 : 的getOutputStream OutputStream getOutputStream() 返回此套接字的输出流。 如果此套接字具有关联的通道,则生成的输出流将其所有操作委托给通道。 如果通道处于非阻塞模式,则输出流的写入操作将抛出IllegalBlockingModeException。 关闭返回的OutputStream将关闭关联的套接字。 这里需要注意的是: 关闭返回的OutputStream将关闭关联的套接字。 在您的代码中,在您写 ... -
检查以下代码: var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor; var ns:Namespace = appXml.namespace(); trace(appXml.ns::version); Check the following code: var appXml:XML = NativeApplic ...
-
如果多个线程使用相同的FILE *,那么如果没有锁定所有对fopen,fclose和fwrite的调用,则可能会遇到许多问题。 当您重新打开文件时,可能会有另一个线程尝试写入该文件。 fwrite也会执行缓冲写入,并且在缓冲区上运行的多个线程可能会导致内存损坏。 If multiple threads are using the same FILE* then there are a number of problems you could be hitting if there isn't a lock ...
-
从另一个线程写入时,我可以从一个线程上读取文件描述符吗?(Can I read from a file descriptor on one thread while writing from another?)[2024-03-07]
是的,你可以使用串口完成,没问题。 您也可以使用常规文件来执行此操作,但这可能会让您感到困惑,因为您必须仔细管理文件的内容,以便读取器和写入器不会相互踩踏并特别小心地管理搜索指针(使用不依赖于搜索指针的pread()和pwrite() )。 显然,由于串行端口具有独立的输入和输出方向,并且没有寻道指针的概念,因此它更直接。 Yes, you can do that with a serial port, no problem. You could do it with a regular file too, ... -
修复:更改/src/ANESampleTest-app.xml第二行的命名空间 FROM:
TO: 简短且不完整的背景:文件/src/ANESampleTest-app.xml是“应用程序描述符文件”。 当使用随教程下载的项目文件(包含3.6参考)时,构建 ... -
我可以测试文件描述符是否为read()的正确类型?(Can I test if a file descriptor is of the right type for read()?)[2021-08-29]
不。您自己引用了规范的相关部分。 实际上,由于各种原因,读取可能随时失败。 测试“将读取成功”,然后read ,仅引入竞争条件 - 两次调用之间的情况可能会发生变化。 您需要以适当处理失败读取的方式编写应用程序。 如果这样做,您通常不需要事先关心测试,只需使用select来确定数据何时(可能)可用。 No. You quoted the relevant part of the specification yourself. Indeed, a read may fail at any time for a ...