Count on an IEnumerable<dynamic>

僤鯓⒐⒋嵵緔 提交于 2019-12-05 10:37:55

Rather than calling it using the extension method member syntax, try calling the static method directly.

int count = Enumerable.Count(queryFromMassiveDynamic);

The question is a bit off. You're not actually doing a count of an IEnumerable<dynamic>. You're trying a count on a dynamic (which hopefully holds an IEnumerable).

The straightforward way to do this is by using a cast:

 var z = (queryFromMassiveDynamic as IEnumerable<dynamic>).Count();

You can take sehe's answer, which is to cast the result.

var z = (queryFromMassiveDynamic as IEnumerable<dynamic>).Count();

Instead, realize what you are getting from the Query member function. You are in fact getting an IEnumerable of type dynamic and var has trouble with those.

Change this line

var queryFromMassiveDynamic = viewModelExpando.TenTricksNewestFirst;

To this

IEnumerable<dynamic> queryFromMassiveDynamic = viewModelExpando.TenTricksNewestFirst;

Count will show up without having to do any casting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!