Click here to Skip to main content
15,917,328 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to know why my Switch statement is not working if I have something like this:

public enum cond
{ checknum,
  checkval
}
private string data()
{ cond condtype = cond.checknum;
  switch (condtype)
  { case cond.checknum:
    // ... code
    break;
  }
}

It looks like never enter in any condtype...

any idea ?
Posted
Updated 11-Oct-10 1:52am
v2

You forgot the colon

C#
private string data()
{ cond condtype = cond.checknum;
  switch (condtype)
  { case cond.checknum:
    // ... code
    break;
  }
}


However, this makes no sense at all. Why do you need a switch to determine what you have already set?
 
Share this answer
 
Comments
jalmonte 11-Oct-10 7:51am    
Exist more than one condition. Furthermore exist more than one case. I just put one to show an example. The colon was already put on the program, I just forget to put here.
[no name] 11-Oct-10 8:13am    
If you want help then I suggest you provide a sample that show everything you are doing and/or explain everything more clearly
This is what I did seems to be working fine for me

C#
class Program
{
    public enum cond
    {
        checknum,
        checkval
    }
    static private void data()
    {
        cond condtype = cond.checknum;
        switch (condtype)
        {
            case cond.checknum:
                Console.WriteLine("I am checknum");
                break;
            case cond.checkval:
                Console.WriteLine("I am checkval");
                break;
            default:
                Console.WriteLine("I am no one");
                break;
        }
    }
    static void Main(string[] args)
    {
        data();
        Console.ReadKey();
    }
}


I suggest you look at other areas of the code for the problem.

HTH
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900