|
-
May 4th, 2007, 07:41 AM
#1
Thread Starter
Fanatic Member
need help in enum
hi, i want to use enum in comsole application.
so i used this
Code:
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Hello there!");
//Console.Write("Please input your name: ");
//string alfa = Console.ReadLine();
//Console.WriteLine("Hello " + alfa + ". I am just a simple machine here to assist you.");
//Console.Read();
Console.WriteLine("{0},{1}",hi.add ,hi.mul);
}
public enum hi : int
{
add=10,
mul=20
}
}
but in output i am getting is
add,mul
no value is comming.
so please help me to get output.
-
May 4th, 2007, 09:10 AM
#2
Hyperactive Member
Re: need help in enum
have you tried?
Console.WriteLine("{0},{1}",(int)hi.add ,(int)hi.mul);
-
May 4th, 2007, 08:55 PM
#3
Re: need help in enum
When you use a format string like Console.WriteLine does, the ToString method of each value is called in order to get a text value to insert into the string. When you call ToString an an enumerated constant you get its name. If you want the numerical values then you need to call the ToString method of the corresponding numbers. You get the corresponding numbers as Rauland has demonstrated.
-
May 7th, 2007, 12:14 AM
#4
Thread Starter
Fanatic Member
Re: need help in enum
hi jmcilhinney ,rauland thanks for your cute reply
-
May 7th, 2007, 01:01 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|