【发布时间】:2013-03-02 20:55:39
【问题描述】:
public enum ENUM_AccDebitCredit
{
accDR = 1,
accCR = 2
}
我在一个类中声明为public ENUM_AccDebitCreditDebitCredit { get; set; }
在我的代码中,我尝试从数据表中填充 enum,如下所示
DebitCredit = (ENUM_TransactionType)Enum.Parse(typeof(ENUM_TransactionType), rsACC_AccountingRules.Tables[0].Rows[0]["DR"].ToString()) & (ENUM_TransactionType)Enum.Parse(typeof(ENUM_TransactionType), rsACC_AccountingRules.Tables[0].Rows[0]["CR"].ToString());
我想在DebitCredit 中存储多个值,我该怎么做
我的数据表如下
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("DR", typeof(string));
table.Columns.Add("CR", typeof(string));
table.Rows.Add(25, "1","2"); // enum values
【问题讨论】:
-
Enum Flags Attribute的可能重复
-
如果您希望枚举的行为类似于标志,请使用
[Flags]属性标记您的枚举。但是,您需要 1、2、4 之类的值(除非 Return 确实既是 Sales 又是 Purchase,这似乎不太可能)并使用|将它们组合起来 -
如果您希望 DebitCredit 成为一个数组,请查看 stackoverflow.com/questions/7031299/…
-
我需要从 Datatable 值中填写