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 ?

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.