C#控制台程序的开发与打包为一个exe文件实例详解

  float num1 = 0; float num2 = 0;

  Console.WriteLine(" C# 控制台计算器

  ");

  Console.WriteLine("------------------------

  ");

  Console.WriteLine("请输入一个数字,然后回车");

  num1 = Convert.ToInt32(Console.ReadLine());

  Console.WriteLine("请输入另一个数字,然后回车");

  num2 = Convert.ToInt32(Console.ReadLine());

  Console.WriteLine("从下面的列表里选择一个选项:");

  Console.WriteLine(" a - 加");

  Console.WriteLine(" s - 减");

  Console.WriteLine(" m - 乘");

  Console.WriteLine(" d - 除");

  Console.Write("你的选择是? ");

  switch (Console.ReadLine())

  {

  case "a":

  Console.WriteLine($"结果: {num1} + {num2} = " + (num1 + num2));

  break;

  case "s":

  Console.WriteLine($"结果: {num1} - {num2} = " + (num1 - num2));

  break;

  case "m":

  Console.WriteLine($"结果: {num1} * {num2} = " + (num1 * num2));

  break;

  case "d":

  Console.WriteLine($"结果: {num1} / {num2} = " + (num1 / num2));

  break;

  }

  Console.Write("按下任意键退出...");

  Console.ReadKey();