Results 1 to 5 of 5

Thread: need help in enum

  1. #1

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    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.
    Loving dotnet

  2. #2
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: need help in enum

    have you tried?

    Console.WriteLine("{0},{1}",(int)hi.add ,(int)hi.mul);

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: need help in enum

    hi jmcilhinney ,rauland thanks for your cute reply
    Loving dotnet

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: need help in enum

    Is this thread Resolved?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width