Tag: 枚举

可能多次枚举IEnumerable?

这是为什么 ? 我该怎么解决?

如何处理“无限”IEnumerable?

“无限”IEnumerable的一个简单例子 IEnumerable Numbers() { int i=0; while(true) { yield return unchecked(i++); } } 我知道 foreach(int i in Numbers().Take(10)) { Console.WriteLine(i); } 和 var q = Numbers(); foreach(int i in q.Take(10)) { Console.WriteLine(i); } 两者都工作正常(并打印出数字0-9)。 但是在复制或处理像q这样的表达式时是否有任何陷阱? 我可以依赖这样一个事实,即它们总是被评估为“懒惰”吗? 产生无限循环有危险吗?

如何在DataGridViewComboBox中显示枚举类型成员?

为了在DatagridViewComboBox中显示ReadAccess枚举成员,我还需要做些什么? ReadDataGridViewComboBoxColumn.Items.Clear(); ReadDataGridViewComboBoxColumn.Items.AddRange(ReadAccess.None, ReadAccess.Allowed); ReadDataGridViewComboBoxColumn.ValueType = typeof(ReadAccess); 这是关于DataGridView的设计器生成的代码: this.rolesDataGridView.AutoGenerateColumns = false; this.rolesDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.TableNameDataGridViewTextBoxColumn, this.ReadDataGridViewComboBoxColumn, this.WriteDataGridViewComboBoxColumn, this.ReadCodeDataGridViewComboBoxColumn, this.ProcessDataGridViewCheckBoxColumn, this.AdministrateDataGridViewCheckBoxColumn}); this.rolesDataGridView.DataSource = this.bsTablePermissions; 最后,在InitializeComponent(); ,我正在设置DataGridView的DataSource: this.rolesDataGridView.DataSource = this.RoleTablePermissions; // a bindingsource list

将附加信息与.NET Enum相关联

我的问题最好用一个例子来说明。 假设我有枚举: public enum ArrowDirection { North, South, East, West } 我想将对应于每个方向的单位向量与该方向相关联。 例如,我想要返回(0,1)for North,(-1,0)for West等等。我知道在Java中你可以在枚举中声明一个可以提供该function的方法。 我当前的解决方案是使用静态方法 – 在定义枚举的类中 – 返回与传递的ArrowDirection相对应的向量(该方法使用HashTable来完成查找,但这并不重要)。 这似乎……不洁净。 题: 是否有最佳实践解决方案来存储与.NET中的枚举相对应的附加信息?

在声明枚举时,是否应该将类型强制为256个实体以下的字节?

如果你的应用程序中有一个枚举而你只有几个项目,你应该强制基础类型是最小的类型吗? enum smaller : byte { one, two, three };

如何创建枚举类型的属性

enum E_Color { red, black }; private E_Color Color { get { return Color; } set { Color = value; } } public Card(int color, int num) { Color = (E_Color)color; Number = num; } 所以这是我的代码,我不知道这是什么问题,我很确定它在这里。 我是c#的新手(我以前用c ++编程),所以我不知道该怎么做。 在编译时运行它但打印“由于StackOverflowException导致进程终止”。 如果我进入它只是停止debuging并完成它到达构造函数。

解析StringValueAttribute以返回Enum

我目前有一个带有使用字符串值属性的枚举的Windows Phone 8.1运行时项目。 我希望能够通过使用字符串值属性来获取枚举值,例如使用“world”来获取summer的枚举值。 我正在使用Windows Phone 8.1运行时因此我发现的大多数方法都不起作用。 提前致谢。 public enum test { [StringValue(“hello”)] school, [StringValue(“world”)] summer, [StringValue(“fall”)] car } public class StringValueAttribute : Attribute { private string _value; public StringValueAttribute(string value) { _value = value; } public string Value { get { return _value; } } }

是否可以在枚举中添加带空格或特殊字符的字符串

HII, 是否可以在枚举中添加带空格或特殊字符的字符串 例如,我有一个像“保险KR用户(名称)”这样的字符串,我试图将此字符串包含在枚举中 public enum MemberGroup { Insurance KR Users (Name) } 但它捕捉错误。 请给我一个解决方案,将这些类型的字符串包含在枚举中。

通过C#reflection获取类的Enum

我有一个Enum喜欢 namespace EnumTest { public class Enumeration { public Enumeration(); public enum Days { day = sunday, night = monday } } } 如何通过反思获取类型信息数天。 Type type = assembly.GetType(Days); Type type = typeof(Days)将返回Type type = typeof(Days)的类型信息。 如果我有String s = “Days” ,使用此字符串s我需要获取Days的类型信息。 我需要类型=天

如何将自定义枚举描述绑定到DataGrid

问题:我有一个枚举类型,其中包含以下样式的描述标记:[URL =“http://xml.indelv.com/data-binding-enum.html”]描述标记教程[/ URL]。 我有一个Windows SQL Server数据库,我从中拉取数据(作为整数然后castine到枚举),然后绑定到数据网格。 我想在枚举类型中显示与其关联的描述标签,而不是拉动和包装枚举类型。 这是ASP – <asp:HyperLinkField DataNavigateUrlFields="statementID" DataNavigateUrlFormatString="~/Gateway/Statements/Update.aspx?statementID={0}" NavigateUrl="~/Gateway/Statements/Update.aspx" HeaderText="Edit" Text="” /> There are no statements to display. 这是绑定的代码 – [码] private void BindData() { IStatementDao statementDao = DaoFactory.GetStatementDao(); List statements; if (Page.Request.RawUrl.Contains(“Gateway”)) { statements = statementDao.GetAll(); StatementGrid.HeaderStyle.CssClass = “GatewayGridHeader”; StatementGrid.AlternatingRowStyle.CssClass = “GatewayGridAlternatingRow”; } else { // This should never be […]