【问题标题】:How to declare variable of the type System.Collections.Generic.IEnumerable?如何声明 System.Collections.Generic.IEnumerable 类型的变量?
【发布时间】:2015-07-11 07:18:12
【问题描述】:

如何只声明System.Collections.Generic.IEnumerable类型的变量?

如果我尝试:

var selectedData="";
type selectedData=null;

我收到错误。

【问题讨论】:

    标签: asp.net webmatrix


    【解决方案1】:

    System.Collections.Generic.IEnumerable<dynamic> 因为来自db.Query 的结果是动态行。 C# 编译器在编译时不知道查询返回的类型。

    【讨论】:

      【解决方案2】:

      只是

      System.Collections.Generic.IEnumerable selectedData;
      

      您可以稍后在代码中使用它。

      【讨论】:

      • 当我尝试时遇到此错误 CS0305: Using the generic type 'System.Collections.Generic.IEnumerable' requires 1 type arguments
      • 如果你想使用泛型类型,那么你应该像这样指定它:System.Collections.Generic.IEnumerable
      • 请解释一下应该是哪种类型?我想通过 System.Collections.Generic.IEnumerable selectedData=db.Query(SelectCategoryQuery,category);对它的价值。我该怎么办?
      猜你喜欢
      • 2015-04-28
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-22
      • 2012-09-05
      • 2012-06-26
      • 1970-01-01
      相关资源
      最近更新 更多