将动态类型转换为列表 [英] Convert Dynamic Type to List
本文介绍了将动态类型转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Facebook C#SDK来获取数据.我想使用parallel.foreach
但不能使用它-而是发生错误:
I am using the Facebook C# SDK to get data. I want to use parallel.foreach
but cannot use it - instead, an error occurs:
在未先将其转换为委托或表达式树类型的情况下,不能将lambda表达式用作动态调度的操作的参数
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
那么我有什么方法可以将检索到的数据转换为列表?
So is there any way I can convert data retrieved to a list?
dynamic friends = app.Get("me/friends");
Parallel.ForEach(friends.data, friendsData =>
{
Interlocked.Increment(ref infoCount);
LoadFriends(friend, infoCount);
});
推荐答案
如果您不能使用lambda表达式,是否尝试过匿名方法?
If you can't use a lambda expression, have you tried an anonymous method?
dynamic friends = app.Get("me/friends");
Parallel.ForEach(friends.data, delegate(dynamic friendsData)
{
Interlocked.Increment(ref infoCount);
LoadFriends(friend, infoCount);
});
这篇关于将动态类型转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文