Solved

C# Get and Set methods

Posted on 2007-04-05
5
23,297 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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