-
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.
-
Re: need help in enum
have you tried?
Console.WriteLine("{0},{1}",(int)hi.add ,(int)hi.mul);
-
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.
-
Re: need help in enum
hi jmcilhinney ,rauland thanks for your cute reply
-
Re: need help in enum