本文介绍了管理枚举到非托管enum metro应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有疑问。
我需要将托管枚举转换为非托管枚举。
Hi,
I have a doubt.
I need to convert managed enum to unmanaged enum.
enum class MANAGED
{
TYPE1,
TYPE2
}
enum UNMANAGED
{
TYPE1,
TYPE2
}
我做了填充码
I did the fillowing code
UNMANAGED unman = (UNMANAGED)((int)man);
但是我得到未定义的值变量 unman
请回复....
提前谢谢..
But i'm getting undefined value in the variable unman
Please reply....
Thanks in advance..
推荐答案
int temp = (int)man; //But "man" must be initialized!
UNMANAGED unman = (UNMANAGED)temp;
MANAGED man = MANAGED.TYPE1;
UNMANAGED un = (UNMANAGED)((int)man);
一个明显的错误是你在这里使用'class: enum class MANAGED 这个词。
这样可行:
An obvious bug is your use of the word 'class here: enum class MANAGED.
This will work:
MANAGED man = MANAGED.TYPE1;
UNMANAGED un = (UNMANAGED) man;
因为每个Enum值都有一个内在数值:不需要转换(到整数)。
Because each Enum value has an intrinsic numeric value: conversion (to integer) is not required.
这篇关于管理枚举到非托管enum metro应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!