除了枚举为C#中使用什么 [英] What to use besides enum for c#

查看:92
本文介绍了除了枚举为C#中使用什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,现在有一个应用程序的状态使用的枚举。但是,使用它针对UI时有什么感觉了。要整型和字符串之间的转换许多填充下拉菜单的时候。我可以用一个扩展方法或类型转换器,并继续使用,这将是有益的,如果枚举中有多个单词的枚举。

So currently have an enumeration used on the status of an application. However, something feels off when using it against the ui. To many conversions between integer and string when populating drop downs. I could use an extension method or the type converter and continue to use the enum which will be helpful if an enum has multiple words in it.

想我会问看到在可能的洞之前,我就掏深填充。

Thought I'd ask to see about filling in a possible hole before I dig it to deep.

感谢。

推荐答案

如果您正在使用有可能状态的有限和知名数的变量工作,那么枚举确实是正确的结构供您使用。有许多可能的方式,使与UI更方便的工作,并且已经举了两个优秀的人,这是类型转换器和扩展方法。

If you are working with a variable that has a finite and well-known number of possible states, then an enum is indeed the correct construct for you to use. There are many possible ways to make working with the UI more convenient, and you have cited two excellent ones, which are type converters and extension methods.

这篇关于除了枚举为C#中使用什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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