Enum.GetValues和Enum.GetNames的区别 [英] Difference between Enum.GetValues and Enum.GetNames

查看:1659
本文介绍了Enum.GetValues和Enum.GetNames的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到 Enum.GetValues 返回基地阵列键入和 Enum.GetNames 返回字符串阵列。但我不明白这是非常显著。对于枚举反正,该值是字符串。

I see the Enum.GetValues returns base Array type and Enum.GetNames returns a string array. But I don't understand how this is very significant. For an enum anyways, the values are strings.

不过,有一个相关的问题。在 DataGridView的 组合框列databinds到枚举如果我给在数据源 = Enum.GetValues ,但是当我给它它不进行数据绑定枚举.GetNames 数据源

But, there is an associated problem. The DataGridView ComboBox column databinds to an enum if I give the DataSource = Enum.GetValues, but it doesn't databind when I give it Enum.GetNames as a DataSource.

推荐答案

的GetValues 将在返回枚举基础值的数组,每个项目

GetValues will return an Array of the underlying values for each item in the Enum.

GetNames 将返回在枚举中的项目名称的字符串数组。

GetNames will return a string array of the Names for the items in the enum.

通过的GetValues返回的数组实现IList而字符串[]由GetNames没有,返回其说明绑定的差异。

The Array returned by GetValues implements IList while the string[] returned by GetNames does not, which explains the binding differences.

这篇关于Enum.GetValues和Enum.GetNames的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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