管理枚举到非托管enum metro应用程序 [英] Managed enum to unmanaged enum metro apps

查看:117
本文介绍了管理枚举到非托管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..

推荐答案

因为你使用的是MANAGED枚举,它不会自动转换为int所以你应该有:

Because your using MANAGED enum it will not be converted automatically to int so you should have:
int temp = (int)man; //But "man" must be initialized!  
UNMANAGED unman = (UNMANAGED)temp;


假设变量'man属于MANAGED类型并被分配,此代码将工作:
Assuming the variable 'man is of Type MANAGED, and is assigned, this code will work:
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应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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