C# 使用表达式树API调用Intersect时出错
我正在学习表达树,所以请在这一点上容忍我 我们的想法是调用intersect以接收num 3 我想我错过了什么。你能告诉我我做错了什么吗C# 使用表达式树API调用Intersect时出错,c#,C#,我正在学习表达树,所以请在这一点上容忍我 我们的想法是调用intersect以接收num 3 我想我错过了什么。你能告诉我我做错了什么吗 static void Main(string[] args) { List<int> arr1 = new List<int> { 1, 2, 3, 4, 5 }; List<int> arr2 = new List<int> { 6, 7, 8, 9, 3 };
static void Main(string[] args)
{
List<int> arr1 = new List<int> { 1, 2, 3, 4, 5 };
List<int> arr2 = new List<int> { 6, 7, 8, 9, 3 };
var ex =
Expression.Lambda<Func<List<int>>>(
Expression.Call(
Expression.Constant(arr1), typeof(List<int>).GetMethod("Intersect"), Expression.Constant(arr2)));
....
static void Main(字符串[]args)
{
List arr1=新列表{1,2,3,4,5};
List arr2=新列表{6,7,8,9,3};
var-ex=
Lambda(
表情,打电话(
Expression.Constant(arr1)、typeof(List.GetMethod(“Intersect”)、Expression.Constant(arr2));
....
为什么这个抛出值不能为null?
Intersect
是扩展方法,所以typeof(List).GetMethod(“Intersect”)
返回null要解决此问题,请尝试从
可枚举的
更新
为了得到交集,试试这个
var intersectMethod = typeof(Enumerable).GetMethods().First(a => a.Name == "Intersect" && a.GetParameters().Count() == 2).MakeGenericMethod(typeof(int));
更好
var intersectMethod = typeof(Enumerable).GetMember("Intersect").First().MakeGenericMethod(typeof(int));
Intersect
是扩展方法,因此typeof(List).GetMethod(“Intersect”)
返回null要解决此问题,请尝试从
可枚举的
更新
为了得到交集,试试这个
var intersectMethod = typeof(Enumerable).GetMethods().First(a => a.Name == "Intersect" && a.GetParameters().Count() == 2).MakeGenericMethod(typeof(int));
更好
var intersectMethod = typeof(Enumerable).GetMember("Intersect").First().MakeGenericMethod(typeof(int));
Intersect
是扩展方法,因此typeof(List).GetMethod(“Intersect”)
返回null要解决此问题,请尝试从
可枚举的
更新
为了得到交集,试试这个
var intersectMethod = typeof(Enumerable).GetMethods().First(a => a.Name == "Intersect" && a.GetParameters().Count() == 2).MakeGenericMethod(typeof(int));
更好
var intersectMethod = typeof(Enumerable).GetMember("Intersect").First().MakeGenericMethod(typeof(int));
Intersect
是扩展方法,因此typeof(List).GetMethod(“Intersect”)
返回null要解决此问题,请尝试从
可枚举的
更新
为了得到交集,试试这个
var intersectMethod = typeof(Enumerable).GetMethods().First(a => a.Name == "Intersect" && a.GetParameters().Count() == 2).MakeGenericMethod(typeof(int));
更好
var intersectMethod = typeof(Enumerable).GetMember("Intersect").First().MakeGenericMethod(typeof(int));
错误到底是什么?错误文本是值不能为空。我在底部写了它。可能重复的错误到底是什么?错误文本是值不能为空。我在底部写了它。可能重复的错误到底是什么?错误文本是值不能为空。我在底部写了它。可能重复的错误是什么tly?错误文本是值不能为空。我在底部写了它。可能是好的建议的副本,但现在我得到未处理的异常:System.Reflection.AmbiguousMatchException:找到了不明确的匹配。有什么想法吗???是的,找到你想要的方法,
public static IEnumerable Intersect(这是IEnumerable first,IEnumerable second);
或公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二,IEqualityComparer比较器)概念:找到不明确的匹配。有什么想法吗???是的,找到你想要的方法,公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二);
或公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二,IEqualityComparer比较器)概念:找到不明确的匹配。有什么想法吗???是的,找到你想要的方法,公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二);
或公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二,IEqualityComparer比较器)概念:找到不明确的匹配。有什么想法吗???是的,找到你想要的方法,公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二);
或公共静态IEnumerable Intersect(此IEnumerable第一,IEnumerable第二,IEqualityComparer比较器)5944?