Results 1 to 6 of 6

Thread: Enumerations

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Enumerations

    i have an enumeration in a class...and i want that 1 function has a parameter that uses that enumeration...how do i do that? i want that when in form1 i type mClass.mFunction i can put in there my enumeration as parameter..i tryed puting the enumeration as public but didnt work

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Make sure your enum is public, then it's fairly straight forward:
    PHP Code:
    namespace MyNamespace
    {
        public 
    enum enumMyEnum
        
    {eElement1 0eElement2eElement3}

        public class 
    Test
        
    {
            public 
    Test()
            {
                
            }

            public 
    string MyFunction(enumMyEnum p_enumParameter)
            {
                return 
    p_enumParameter.ToString();
            }
        }

    You either have to add a namaspace to your form or use a full qualifyer for the enum:
    PHP Code:
    private void button1_Click(object senderSystem.EventArgs e)
    {
        
    string strSomeValue;
        
    MyNamespace.Test objMyClass = new MyNamespace.Test();

        
    strSomeValue objMyClass.MyFunction(MyNamespace.enumMyEnum.eElement1);


  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    do i really have to put that class in another namespace?

  4. #4
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    Everything's got to be under a namespace...
    -scott
    he he he

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    lol but i am under the form1 namespace lol

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    If you are making creating that class in form1 then thats ok, however If you are creating the class in a separate file, then you can either use the form1 namespace or create a new one.
    Dont gain the world and lose your soul

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