Skip to main content
 首页 » 编程设计

c#之将动态类型转换为列表

2024年02月23日18yyy_WW

我正在使用 Facebook C# SDK 获取数据。我想使用 parallel.foreach 但不能使用它 - 相反,会发生错误:

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

那么有什么方法可以将检索到的数据转换为列表吗?

dynamic friends = app.Get("me/friends");    
Parallel.ForEach(friends.data, friendsData => 
    { 
        Interlocked.Increment(ref infoCount); 
        LoadFriends(friend, infoCount); 
    }); 

请您参考如下方法:

如果你不能使用lambda表达式,你试过匿名方法吗?

dynamic friends = app.Get("me/friends");    
    Parallel.ForEach(friends.data, delegate(dynamic friendsData) 
       { 
           Interlocked.Increment(ref infoCount); 
           LoadFriends(friend, infoCount); 
 
       });