【发布时间】:2012-08-16 17:59:06
【问题描述】:
我使用这个方法来填充网格视图的数据源,但是当getnew 是false 时,它不会返回任何值,只是返回一个包含单个空值的列表。
private List<T> GetAll_T(bool getNew)
{
if (getNew)
return (ViewState["T"] = Get_T()) as List<T>;
//Get_T() returns a CustomList
return new List<T>
{
ViewState["T"] != null ?
ViewState["T"] as T:
(T)(ViewState["T"] = Get_T()) Collection
};
}
它给了我第二行的警告[当视图状态为空时]。表达式总是错误的
为什么会有警告,当它在逻辑上是正确的时候!
【问题讨论】:
标签: asp.net c#-4.0 object-initializers