gpt4 book ai didi

c# - 如何从枚举中获取字符串值

转载 作者:太空狗 更新时间:2023-10-29 21:21:21 26 4
gpt4 key购买 nike

<分区>

我对枚举感到困惑。这是我的枚举

enum Status
{
Success = 1,
Error = 0
}


public void CreateStatus(int enumId , string userName)
{
Customer t = new Customer();
t.Name = userName;
// t.Status = (Status)status.ToString(); - throws build error
t.Status = //here I am trying if I pass 1 Status ="Success", if I pass 0 Status = "Error"

}

Error - Cannot convert string to enum.Status

public class Customer
{
public string Name { get; set;}
public string Status {get; set;}
}

如何使用枚举状态设置客户对象的状态属性?

(无 If-Else 或切换阶梯)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com