C# Get and Set methods

mitesh114 used Ask the Experts™
I have a class called Settings and I have this method in there:
public enum Scope
scopeone  = 0,
scopetwo = 1,
scopethree = 2                  
public Settings.Scope SelectScope
get{ return _selectScope; }
set{ _selectScope = value; }

I then have another method called MessageBox in which I want to display the scope value picked up from the dropdown.  How do I do this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
public void MessageB()
      //For testing purposes:
      _selectScope = Scope.scopeone;

.ToString()  will give a string name of the enum.  If you want the original number, you will have to create your own ToString() function and output the numeric value.

MessageBox.Show(Enum.GetName(typeof(Scope), _selectScope);
Sorry, not override the ToString() Function (since that's in the enumerator)
What you can do is to show the numeric value of your enumator is to say

MessageBox.Show( (  ((int)_selectScore).ToString() );
Where you cast your enum into an integer first.

Hope this helps :)


thanks for your help
No problem, thanks too!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial