0

i'm having a syntax error when trying to use switch condition:
control cannot fall through from one case label to another...

my code is

public override Boolean intersect(Shape s)
        {
            switch (s.GetType().Name)
            {
                case "RealPoint":
                   {
                        s = (RealPoint)s;

                        if (!(this.gspos > s.gspos) && !(this.gspos < s.gspos))
                            return true;
                    }

                case "Segment":
                    {
                        Size tsize;
                        tsize = s.gspos - this.gspos;
                        s = (Segment)s;

                        if (tsize.gsy == 0 && this.gspos.pgsx >= s.gspos.pgsx && this.gspos.pgsx <= (s.gspos.pgsx + s.gsize.gsx))
                            return true;
                    }

            }
                    return false;
        }

how can i fix ?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by emilio
0

The reason is that the compiler can see that there is the possibility that the condiotnal statement could be false, and therefore it can fall through to the next case statement.. which is illigal. So to fix the problem, always be sure that the case either returns, or does a break; as the last statement in each case statement.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.