简体   繁体   English

如何转换system.linq.IQueryable <int?> 诠释?[]

[英]how to convert system.linq.IQueryable<int?> to int?[]

foreach (var app in allList)
{
    int?[] ids = Context.tblTransactionDetails
        .Where(x => x.IsActive == true)
        .Select(x => x.AdvertID);
}

In C#, T[] designates an array of elements of type T . 在C#中, T[]指定类型T的元素数组 In order to obtain an array from a sequence, use ToArray() extension method: 为了从序列中获取数组,请使用ToArray()扩展方法:

foreach (var app in allList)
{
    int?[] ids = Context.tblTransactionDetails
        .Where(x => x.IsActive == true)
        .Select(x => x.AdvertID)
        .ToArray();
}

Note that this will evaluate the expression and load all the elements of the sequence to memory. 请注意,这将计算表达式并将该序列的所有元素加载到内存中。 If you don't need all the elements at the same time (in most cases, you really don't), this may not be what you want. 如果您不需要同时使用所有元素(在大多数情况下,您实际上并不需要),那么可能就不是您想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型'System.Linq.IQueryable <int>'隐式转换为'int?' - Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?' 无法转换类型&#39;System.Linq.IQueryable <int> &#39;到&#39;int&#39; - Cannot convert type 'System.Linq.IQueryable<int>' to 'int' 错误:实例参数:无法从&#39;int&#39;转换为&#39;System.Linq.IQueryable <int> “ - Error :Instance argument: cannot convert from 'int' to 'System.Linq.IQueryable<int>' 运算符&#39;==&#39;不能应用于&#39;int&#39;和&#39;System.Linq.iQueryable类型的操作数 <int> “ - Operator '==' cannot be applied to operands of type 'int' and 'System.Linq.iQueryable<int>' Linq查询结果不支持类型&#39;System.Linq.IQueryable`1 [System.Int32]的比较运算符 - Linq query results in Comparison operators not supported for type 'System.Linq.IQueryable`1[System.Int32] c#-Linq错误“运算符&#39;==&#39;无法应用于类型为&#39;int&#39;和&#39;System.Linq.IQueryable的操作数 <T> ”和RemoveRange - c# - Linq Error “Operator '==' cannot be applied to operands of type 'int' and 'System.Linq.IQueryable<T>” and RemoveRange 无法隐式转换类型&#39;System.Linq.IQueryable <AnonymousType#1> &#39;到&#39;System.Linq.IQueryable &lt;&gt;&#39; - Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<>' 将System.Linq.IQueryable转换为System.Collections.Generic.ICollection - Convert System.Linq.IQueryable to System.Collections.Generic.ICollection System.Linq.IQueryable错误 - System.Linq.IQueryable Error 如何转换&#39;System.Linq.IQueryable <System.Collections.Generic.ICollection<ApplicationUser> &gt;至IList <ApplicationUser> ? - How can I convert a 'System.Linq.IQueryable<System.Collections.Generic.ICollection<ApplicationUser>> to IList<ApplicationUser>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM