By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

using toString with Enumeration

P: n/a
Hey, this is a very basic question for all you csharpers...

I have created a class:

public class Answer
{
public enum theAnswer { A, B, C }
}

I want to be able to do a toString as below on my enumeration... but
cant figure out the syntax to put in my class!!!

theAnswer myAnswer;
string myString;

ans = myAnswer.A;
mystring = ans.toString

Sep 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

FYI it's much better practice to declare public enums in a namesapce, not a class declaration, and to use Pascal casing as you would
a class or struct declaration:

namespace TopNamespace
{
public enum TheAnswer
{
A, B, C
}

public class Answer
{
public Answer() // instance constructor
{
TheAnswer myAnswer = TheAnswer.A;
string myString = myAnswer.ToString();

// myString now contains "A"
}
}
}
--
Dave Sexton

"csharpers" <la*****@gmail.comwrote in message news:11**********************@e3g2000cwe.googlegro ups.com...
Hey, this is a very basic question for all you csharpers...

I have created a class:

public class Answer
{
public enum theAnswer { A, B, C }
}

I want to be able to do a toString as below on my enumeration... but
cant figure out the syntax to put in my class!!!

theAnswer myAnswer;
string myString;

ans = myAnswer.A;
mystring = ans.toString

Sep 26 '06 #2

P: n/a
Thanks

Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.