C#案例陈述问题

时间:2011-08-05 11:49:31

标签: c# windows-phone-7 windows-phone

为WP7制作应用程序,但遇到了此case语句错误。它出现在第3个案例中。给出“不能通过案例错误”。我已经用Google搜索了这个错误,除非我没有正确地集中注意力,否则我确定我已经正确设置了所有内容。

private void SortFeedData(int fs)
    {
        //only using cases 1,2,3 since 0 is for the news page which doesn't need sorting
        switch (fs)
        {
            case 1:
                //Sort feed data for "Scores" Page
                switch (ButtonSourceLeague)
                {
                    case "Premier League":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "Championship":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - Test feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/engchamp-league.aspx");
                        break;
                    case "League One":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "League Two":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "FA Cup":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/fa-cup.aspx");
                        break;
                    case "League Cup":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/english-league-cup.aspx");
                        break;
                    default:
                        MessageBox.Show("Error");
                        break;
                }

                break;
            case 2:
                //Sort feed data for "Fixtures" Page

                switch (ButtonSourceLeague)
                {
                    case "Premier League":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "Championship":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - Test feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/RssTestFeed.aspx");
                        break;
                    case "League One":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "League Two":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "FA Cup":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    case "League Cup":
                        //clears all current feed data
                        App.Data.FeedList.Clear();
                        //For News Page - BBC Football RSS Feed
                        App.Data.FeedList.Add("http://www.rsslivescores.com/premier-league.aspx");
                        break;
                    default:
                        MessageBox.Show("Error");
                        break;
                }
                //Sort feed data for "My Club" Page

                //Either a big-ass case statment for EVERY club we know off
                //OR find a SINGLE rss feed that has info on ALL clubs

                break;
            case 3:

                switch (ButtonSourceClub)
                {

                    case "Manchester United":

                        App.Data.FeedList.Add("rss xml link here");
                        break;
                    default:
                        MessageBox.Show("Error");
                        break;
                }
        }
    }


}

}

3 个答案:

答案 0 :(得分:5)

        case 3:

            switch (ButtonSourceClub)
            {

                case "Manchester United":

                    App.Data.FeedList.Add("rss xml link here");
                    break;
                default:
                    MessageBox.Show("Error");
                    break;
            }
            break; //Here's what you're missing.

答案 1 :(得分:5)

case 3:中,您在内部break之外没有switch语句。因此,有一个隐含的下降到下一个语句(即使没有下一个语句)。

答案 2 :(得分:3)

第三种情况错过了break声明:

            break;
        case 3:

            switch (ButtonSourceClub)
            {

                case "Manchester United":

                    App.Data.FeedList.Add("rss xml link here");
                    break;
                default:
                    MessageBox.Show("Error");
                    break;
            }
            break; // <---- was missing
    }