Q: property problem (enum)

D

dllhell

hi all,

I want to create a property in class (datatype=enum).
In one other class I have declaration of enum:

public enum enumCrep

{

cRep1 = 1,

cRep2 = 2,

}



now, I want to create a property:

public enumCrep ecRep

{

get { return this.ecRep;}

set {this.ecRep = value;}

}



at the moment of asignig a value to this propery its raises error:

{Cannot evaluate expression because the current thread is in a stack
overflow state.}



thanks for help in advance
 
K

Kalpesh

Hi,

You need a member variable to hold the value of the enum

eg
protected enumCrep mecRep

public enumCrep ecRep
{

get { return mecRep;}

set {mecRep = value;}
}

Your code goes into recursion (i.e. you are setting property which is
in-turn calling the code which sets it again)

HTH
Kalpesh
 
K

Kevin Spencer

Youre property is referencing itself, which causes a stack overflow due to
infinte recursion. Try:

private enumCrep _ecRep;
public enumCrep ecRep
{
get { return _ecRep;}
set {_ecRep = value;}
}

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

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

Top