编译出现以下错误:
Microsoft (R) Visual C# .NET 编译器版本 7.10.6001.4
用于 Microsoft (R) .NET Framework 版本 1.1.4322
版权所有 (C) Microsoft Corporation 2001-2002。保留所有权利。SiteManager.cs(33,4): error CS0163: 控制不能从一个 case 标签(“default:”)贯穿到另一个 case 标签
SiteManager.cs(91,7): error CS0117: “string”并不包含对“ToInt32”的定义
SiteManager.cs(93,18): error CS0117: “string”并不包含对“ToInt32”的定义Code如下:
===================================using System;
using WebSites;
class SiteManager
{
SiteList sites = new SiteList();
public static void Main()
{
SiteManager mgr = new SiteManager();
mgr.sites = new SiteList();
mgr.sites[mgr.sites.NextIndex] = new WebSite("Joe","http://www.mysite.com","Great Site.");
mgr.sites[mgr.sites.NextIndex] = new WebSite("Don","http://www.dondotnet.com","Must See.");
mgr.sites[mgr.sites.NextIndex] = new WebSite("Bob","www.bob.com","No http://");

mgr.ShowMenu();
}

public void ShowMenu()
{
string choice;
do
{
Console.WriteLine("Web Site Editor\n");

Console.WriteLine("A - Add");
Console.WriteLine("D - Delete");
Console.WriteLine("M - Modify");
Console.WriteLine("R - Report");
Console.WriteLine("Q - Quit");

Console.Write("\nPlease Choose: ");

choice = Console.ReadLine();
switch (choice.ToUpper())
{
case "A":
AddSite();
break;
case "D":
DeleteSite();
break;
case "M":
ModifySite();
break;
case "R":
ViewSites();
break;
case "Q":
choice = "Q";
break;
default:
Console.WriteLine("({0})?Err...That's not what I expected.",choice);
}
}while(choice != "Q");
}

private void AddSite()
{
string siteName;
string url;
string description;

Console.Write("Please Enter Site Name:");
siteName = Console.ReadLine();

Console.Write("Please Enter URL:");
url = Console.ReadLine();

Console.Write("Please Enter Description:");
description = Console.ReadLine();

sites[sites.NextIndex] = new WebSite(siteName,url,description);
}

private void DeleteSite()
{
string choice;

do
{
Console.WriteLine("\nDeletion Menu\n");
DisplayShortList();
Console.Write("\nPlease select an item to delete:");

choice = Console.ReadLine();

if(choice == "Q" || choice == "q")
{
break;
}

if(choice.ToInt32() <= sites.NextIndex)
{
sites.Remove(choice.ToInt32()-1);
}
}while(true);
}

private void ModifySite()
{
Console.WriteLine("Modifying Sites.");
}

private void ViewSites()
{
Console.WriteLine("");
for(int i=0;i<sites.NextIndex;i++)
{
Console.WriteLine("Site:{0}",sites[i].ToString());
}
Console.WriteLine("");
}

private void DisplayShortList()
{
for(int i=0;i<sites.NextIndex;i++)
{
Console.WriteLine("{0}  -   {1}",i+1,sites[i].ToString());
}
Console.WriteLine("Q - Quit(Back To Main Menu)");
}
}

解决方案 »

  1.   

    System.Convert.ToInt32(choice);
    另外一个毛病不清楚,后面加 break 看看
      

  2.   

    default:
    Console.WriteLine("({0})?Err...That's not what I expected.",choice);
    加入-----break;
      

  3.   

    在default那个分支里面加上 break语句
      

  4.   

    default:
    也是需要加break的。
      

  5.   

    我用了这个方法:
    System.Convert.ToInt32(choice);
    另外一个毛病不清楚,后面加 break 看看
    编译出现如下错误:
    Microsoft (R) Visual C# .NET 编译器版本 7.10.6001.4
    用于 Microsoft (R) .NET Framework 版本 1.1.4322
    版权所有 (C) Microsoft Corporation 2001-2002。保留所有权利。SiteManager.cs(92,7): error CS0117: “string”并不包含对“Convert”的定义
    SiteManager.cs(94,18): error CS0117: “string”并不包含对“Convert”的定义
      

  6.   

    因为你的choice不是由数字组成的字符串!!!