我有这样的模型类:
public class TypeMinimal : BaseMinimal {
private string _name = "";
public TypeMinimal(int? id, string name = "")
: base(id, "types", API.Enum.Types) {
_name = name;
}
[DataMember]
public string name { get { return _name; } set { _name = value; } }
}
Run Code Online (Sandbox Code Playgroud)
我试图根据类型是1还是2来填充属性.例如
type = new TypeMinimal(item.Type == 1 ? 1 : 2)
Run Code Online (Sandbox Code Playgroud)
我想将类型名称和类型ID添加到属性,但我不确定语法.这是我尝试过的但是不正确:
type = new TypeMinimal(item.Type == 1 ? 1, "volunteer" : 2, "staff"),
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
type = item.Type == 1 ? new TypeMinimal(1, "volunteer") : new TypeMinimal(2, "staff");
Run Code Online (Sandbox Code Playgroud)