在不同的案例中使用案例

时间:2016-11-14 11:07:25

标签: c# visual-studio

我需要使用"案例2"内部"案例3",但每次我这样做,它都不起作用。 有人能帮我吗? 我不知道我是否在代码中做错了什么......

我希望你们中的一些人可以帮助我。

我目前使用的代码:

case 2:
    Console.WriteLine("Gekozen actie: 2. Gegevens MP3 speler opslaan");
    Console.WriteLine("Type de ID: ");
    int id = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Type de Maker: ");
    string MAKE = Convert.ToString(Console.ReadLine());
    Console.WriteLine("Type de Model : ");
    var MODEL = Convert.ToString(Console.ReadLine());
    Console.WriteLine("Type de MBGrootte: ");
    int MBSize = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Type de Prijs: ");
    var PRICE = Convert.ToString(Console.ReadLine());                                
    Console.ReadLine();
    Console.WriteLine("Ingevoerde gegevens: " +
        Environment.NewLine + "Uw ID: " + id +
        Environment.NewLine + "Uw Maker: " + MAKE +
        Environment.NewLine + "Uw Model: " + MODEL +
        Environment.NewLine + "Uw MBGrootte: " + MBSize +
        Environment.NewLine + "Uw Prijs: " + PRICE);
    Console.ReadLine();

    break;

case 3:
    Console.WriteLine("ID: 1" +
        Environment.NewLine + "Make: Get Technologies .inc" +
        Environment.NewLine + "Model: HF 410" +
        Environment.NewLine + "MBSize: 4096" +
        Environment.NewLine + "Price: $129.95");
    Console.ReadLine();

    break;

(我需要"案例2"以下#34;案例3"(在Console.ReadLine()下)抱歉我的英语不好!

2 个答案:

答案 0 :(得分:1)

将您的Case 2放入方法中,然后在Case 2Case 3

中使用此方法

答案 1 :(得分:1)

case 2:
case 3:

if (yourVar == 3)
{
  Console.WriteLine("ID: 1" + Environment.NewLine + 
      "Make: Get Technologies .inc" + Environment.NewLine +
      "Model: HF 410" + Environment.NewLine +
      "MBSize: 4096" + Environment.NewLine + "Price: $129.95");

  Console.ReadLine();    
}

Console.WriteLine("Gekozen actie: 2. Gegevens MP3 speler opslaan");
Console.WriteLine("Type de ID: ");
int id = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Type de Maker: ");
string MAKE = Convert.ToString(Console.ReadLine());
Console.WriteLine("Type de Model : ");
var MODEL = Convert.ToString(Console.ReadLine());
Console.WriteLine("Type de MBGrootte: ");
int MBSize = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Type de Prijs: ");
var PRICE = Convert.ToString(Console.ReadLine());
Console.ReadLine();

Console.WriteLine("Ingevoerde gegevens: " +
Environment.NewLine + "Uw ID: " + id +
Environment.NewLine + "Uw Maker: " + MAKE +
Environment.NewLine + "Uw Model: " + MODEL +
Environment.NewLine + "Uw MBGrootte: " + MBSize +
Environment.NewLine + "Uw Prijs: " + PRICE);
Console.ReadLine();
break;