Stack Overflow in C#

后端 未结 1 1763
-上瘾入骨i
-上瘾入骨i 2021-01-25 21:59

I have this register that registers all the objects I need:

public static class ObjectRegister
{
    public static List RegisteredObjects = new Li         


        
相关标签:
1条回答
  • 2021-01-25 22:54

    This is your problem, in Object1:

    public parametar param { get { return this.param; } set { this.param = value; }
    

    That property calls itself recursively - which is exactly why you're getting a stack overflow. Don't do that. Instead, you probably either want an automatically-implemented property:

    public parameter param { get; set; }
    

    or use a private backing field:

    private parametar param;
    public parametar Param { get { return param; } set { param = value; }
    

    Additionally, I'd strongly recommend that you start following .NET naming conventions, and pay attention to spelling in type and member names.

    So you probably want your class to be called Parameter - although personally I'd at least try to make it a little bit more descriptive, e.g. QueryParameter or something similar. Likewise Object1 isn't exactly a semantically-meaningful name - I hope it's not the name in your real code.

    0 讨论(0)
提交回复
热议问题