【发布时间】:2016-09-19 10:31:35
【问题描述】:
我有两个班级:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool isActif { get; set; }
public Product[] Product { get; set; }
}
public class Product
{
public string Id { get; set; }
}
还有两个实例:
Customer Customer1 = new Customer
{
FirstName = "FirstName1",
LastName = "LastName1",
isActif = true,
Product = new Product[]
{
new Product()
{
Id = "1"
}
}
};
Customer Customer2 = new Customer
{
FirstName = "FirstName2",
LastName = "LastName2",
isActif = false,
Product = new Product[]
{
new Product()
{
Id = "2"
}
}
};
我有一种方法可以比较两个实例的所有属性:
但是当我到达Product 属性时,我生成了一个StackOverflowException。为什么 ?如果它是一个数组,如何循环该属性?
编辑:当我使用列表时,不是StackOverflowException,而是System.Reflection.TargetParameterCountException。如果是数组,如何循环属性
【问题讨论】:
-
您是否对代码进行了调试以找出堆栈溢出的原因?
-
这看起来像是重复的。 stackoverflow.com/questions/3747572/…
-
这个建议的答案可能会有所帮助:stackoverflow.com/a/4879978/6256551
标签: c# exception recursion reflection stack-overflow