更新时间:2023-02-26 11:11:52
那么,第一个问题可以通过使用来解决这个代替:
Well, the first problem can be solved using this instead:
var PrintURL = currurl + (String.IsNullOrEmpty(querystring) ?
HttpContext.Current.Request.QueryString.Add("print", "y") : string.Empty);
所有这一切从原来的code改变时只需将关闭括号从(String.IsNullOrEmpty(查询字符串))
(它是不必要的),以结束的:
条款。这使得它明确清楚你想要做的事。
否则,编译器试图串联的 String.IsNullOrEmpty(查询字符串)
(这是一个布尔
)以 currUrl - 不正确的,你首先希望不要什么。
All that's changed from your original code is simply moving the closing paren from (String.IsNullOrEmpty(querystring))
(where it was unnecessary) to the end of the ?:
clause. This makes it explicitly clear what you're trying to do.
Otherwise, the compiler tries to concatenate the result of String.IsNullOrEmpty(querystring)
(which is a bool
) to currUrl
-- incorrect, and not what you intended in the first place.
不过,你有一个第二个问题 HttpContext.Current.Request.QueryString.Add(打印,Y)
语句。这将返回无效
,不是字符串
。你需要修改这部分的三元EX pression,使其返回一个字符串 - 什么是你想怎么办
However, you've got a second problem with the HttpContext.Current.Request.QueryString.Add("print", "y")
statement. This returns void
, not a string
. You'll need to modify this part of your ternary expression so that it returns a string -- what are you trying to do?