Problem with ForEach Parsing

Topics: Developer Forum
Jul 24, 2008 at 7:57 PM
Hello,

I have encountered a small problem in the parsing. I am writing a parser for conditional statements. Following is the code snippet I am working upon:
The Foreach statement block is not populated (count = 0) by the C# parser...Is there someone else who has seen the same problem?
thanx 
public void DisplayEnum()
        {
            string[] list = { "ab", "bc", "cd" };
            using (UsingExample example = new UsingExample())
            {
                StringBuilder anothertest = getSb();
                int test = 0;
                int test1 = 1;
                if (first == MyFirst.First || test == 0)
                {
                    PrintFirst();
                    //else if (first == MyFirst.Second)
                    //PrintSecond();
                    if (first == MyFirst.Third)
                    {
                        if (test == 0)
                        {
                            foreach (string s in list)
                            {
                                if (test1 == 1)
                                    PrintThird();
                            }
                        }
                    }
                }
            }
            Console.Read();
        }
Jul 24, 2008 at 11:29 PM
My bad... I was treating the if condition nested in the foreach statement (in the snippet given below) as a nested block of the foreach statement... 
                foreach (string s in list)
                            {
                                if (test1 == 1)
                                    PrintThird();
                            }
however this is not the case as the parser considers and populates the nested if condition in a separate block...