Solved

C# Get and Set methods

Posted on 2007-04-05
5
23,300 Views
Last Modified: 2011-09-20
Hi,
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?
0
Comment
Question by:mitesh114
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 5

Expert Comment

by:Yttribium
ID: 18856476
public void MessageB()
{
      //For testing purposes:
      _selectScope = Scope.scopeone;
      MessageBox.Show(_selectScope.ToString());
}

.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.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 18856481
MessageBox.Show(Enum.GetName(typeof(Scope), _selectScope);
0
 
LVL 5

Accepted Solution

by:
Yttribium earned 500 total points
ID: 18856484
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 :)
0
 

Author Comment

by:mitesh114
ID: 18856519
thanks for your help
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18856538
No problem, thanks too!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question