PROPERTY PROBLEM

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

wHen i set CokSatan in my page load event it returns stack overflow..

When i try it step by step it stucks at

this.CokSatan = value; line.



what is the problem ?





class myclass : Controls.RProductList

{


public string CokSatan

{

get

{

return this.CokSatan;

}

set

{

this.CokSatan = value;


}

}

public override void GenerateSQL()

{

if (base.SQL_Top == string.Empty)

{

base.SQL = this.CokSatan ;

base.SQL = this.AddOrderBySQL(base.SQL);

base.GenerateSQL();

}

}

}



AND

private void Page_Load(object sender, System.EventArgs e)

{



myclass xclass= new myclass();

xclass.CokSatan =(Rproductlist22.getSQL(string.Empty));
 
wHen i set CokSatan in my page load event it returns stack overflow..

When i try it step by step it stucks at

this.CokSatan = value; line.

what is the problem ?

class myclass : Controls.RProductList

{

public string CokSatan

{

get

{

return this.CokSatan;

}

set

{

this.CokSatan = value;

}
}

public override void GenerateSQL()

{

if (base.SQL_Top == string.Empty)

{

base.SQL = this.CokSatan ;

base.SQL = this.AddOrderBySQL(base.SQL);

base.GenerateSQL();

}
}
}

AND

private void Page_Load(object sender, System.EventArgs e)

{

myclass xclass= new myclass();

xclass.CokSatan =(Rproductlist22.getSQL(string.Empty));


Er, yes, it would.

You are returning (and setting) the actual property name. So, what is
going to happen here?

You call x.CokSatan = "This is a test";

This calls the property set function, which sets the PROPERTY CokSatan
to a string, which
of course calls the property set function, which sets the PROPERTY ..
well, you get the idea.
You are recursing things to death. What you want is this:

class myclass : Controls.RProductList
{
private string okSatanString = "";
public string CokSatan
{
get { return this.okSatanString; }
set { this.okSatanString = value; }
}
}

See the difference? One is a property name, the other is a member
variable.

matt
 
You are referring to the property _not_ the property backing field.

This will cause a stack overflow because it is recursive.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top