Solved

C# Get and Set methods

Posted on 2007-04-05
5
23,293 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
  • 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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