gpt4 book ai didi

c# - 返回一个具有空值的类

转载 作者:行者123 更新时间:2023-12-02 04:39:52 27 4
gpt4 key购买 nike

我有以下代码。
如果没有 WType 为空,我喜欢返回一个空类,其中 Key 和 Value 为空字符串。我收到一个“;”的错误是期待。

返回类型需要是:

IEnumerable<WportType>

代码如下:

if (wType == "Riconda")
{
return dbContext.data_LookupValues
.Where(w => w.Category == "WLoc")
.OrderBy(w => w.SortId)
.Select(a => new WportType
{
Key = a.Key,
Value = a.Value
});

}
else
{
return WportType
{
Key = "",
Value = ""
};
}

最佳答案

您的方法似乎返回了一个 IEnumerable<WportType> .您正在尝试退回单件商品。您需要将其包装在一个集合中:

如下所示:

    if (wType == "Riconda")
{
return dbContext.data_LookupValues
.Where(w => w.Category == "WLoc")
.OrderBy(w => w.SortId)
.Select(a => new WportType
{
Key = a.Key,
Value = a.Value
});

}
else
{
return new[] { new WportType { Key = "", Value = "" } };
}

关于c# - 返回一个具有空值的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099203/

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