在C#中,我如何使用像枚举一样的struct? [英] In C#, how do I use struct like an enum?

查看:83
本文介绍了在C#中,我如何使用像枚举一样的struct?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图用这样一个枚举一个结构:

 公共结构SQLDS_statementTypes 
{
酒店的公共静态字符串选择=选择,
=更新更新,插入=插入,删除=删除;
}



但它抛出一个错误:运算符'=='不能应用于类型的操作数'SQLDS_statementTypes'和'串'。这个语句:

 如果(陈述= = SQLDS_statementTypes.Update)

反正是有解决这个问题?


< DIV CLASS =h2_lin>解决方案

你为什么不使用常规的枚举? http://msdn.microsoft.com/en-us/library/sbbt4032.aspx


I have a struct that I am trying to use like an enum:

public struct SQLDS_statementTypes
{
    public static string Select = "Select", 
        Update = "Update", Insert = "Insert", Delete = "Delete";
}

But it throw an error: "Operator '==' cannot be applied to operands of type 'SQLDS_statementTypes' and 'string'" on this statement:

if (statement == SQLDS_statementTypes.Update)

Is there anyway to solve this?

解决方案

why don't you use regular enum? http://msdn.microsoft.com/en-us/library/sbbt4032.aspx

这篇关于在C#中,我如何使用像枚举一样的struct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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