Enum.GetValues和Enum.GetNames的区别 [英] Difference between Enum.GetValues and 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屋!