gpt4 book ai didi

c# - 来自内部调用的函数的输出字符串 @{}

转载 作者:太空宇宙 更新时间:2023-11-03 20:13:19 24 4
gpt4 key购买 nike

我遇到的问题是在调用以下函数时简单地返回一个字符串:

@{StringUtil.IfNullorEmptyOutputHyphen<decimal>(ViewBag.StockItem.Height);}

这里需要@{},因为参数可能为空,因此需要类型约束。

@StringUtil.IfNullorEmptyOutputHyphen<decimal>(ViewBag.StockItem.Height)

上面给出的错误是因为

<decimal>

因此调用@{}内的函数就变得很有必要了。

完整性的函数是:

public static IHtmlString IfNullorEmptyOutputHyphen<T>(T? value) where T : struct
{
if (value == null)
{
return new HtmlString("wtf99");
}

return new HtmlString(value.ToString());
}

总而言之,我如何从在@{} 中调用的函数返回一个“字符串”

最佳答案

你可以用括号括起来:

@(StringUtil.IfNullorEmptyOutputHyphen<decimal>(ViewBag.StockItem.Height))

关于c# - 来自内部调用的函数的输出字符串 @{},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18506417/

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