分配变量枚举值

时间:2015-12-14 19:15:05

标签: c# enums

我有以下枚举

public enum Outcome
{
   DontKnow = 0,
   Good = 1,
   Bad = 2,
   NotBad = 3
}

在我的Results类中,我有一个包含此枚举的属性:

public class Result
{
   public int Id { get; set; }
   public string Name { get; set; }
   public Outcome FinalOutcome { get; set; }
}

当我从数据库中读取数据时 - 使用SqlDataReader - 如何分配其值?

while(reader.Read())
{
   Id = Convert.IsDbNull(reader[0]) ? Convert.ToInt32(0) : Convert.ToInt32(reader[0]);
   Name = Convert.IsDbNull(reader[1]) ? string.Empty : reader[1].ToString();
   FinalOutcome = Convert.IsDbNull(reader[2]) ? WhatGoesHere? : WhatGoesHere?;
}

2 个答案:

答案 0 :(得分:3)

#include "usb.h"
int main(int argc, char** argv) {
    usb_init();
    printf("usb_find_busses: %d\n", usb_find_busses());
    printf("usb_find_devices: %d\n", usb_find_devices());
}

答案 1 :(得分:0)

假设您的源列是可以为空的int:

FinalOutcome = !Convert.IsDbNull(reader[2]) ?(OutCome)reader[2] : (OutCome)0;
相关问题