Solved

C# Get and Set methods

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Round up to 100% in .NET 10 80
VB.NET HttpWebRequest 12 55
How can I set a timer to automatically take a picture using the Xamarin MediaPlugin 2 45
Error in JQuery 5 35
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now