我是程序设计的初学者,我必须上大学做一个项目。您能告诉我,如何使用在main中创建的开关调用类?
我的主开关有一个,选择了一个选项之后,我希望它显示下一个开关。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerServiceTSz
{
class Priceofservices
{
void SuperSwitch()
{
{
int x = 0;
Console.WriteLine("Please, choose type of service.");
Console.WriteLine("1 - Cleaning");
Console.WriteLine("2 - Repair");
Console.WriteLine("3 - Upgrade");
x = int.Parse(Console.ReadLine());
switch (x)
{
case 1:
{
}
break;
case 2:
{
}
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerServiceTSz
{
class Program
{
static void Main(string[] args)
{
bool done = false;
while(!done)
{
{
int x = 0;
Console.WriteLine("Welcome to computer repair automatic helpdesk.");
Console.WriteLine("1 - List of currently avaivable servisants");
Console.WriteLine("2 - List of services");
Console.WriteLine("3 - Price of services");
Console.WriteLine("4 - Quit");
Console.WriteLine("<------------------------------------------------------>");
x = int.Parse(Console.ReadLine());
switch (x)
{
case 1:
{
List<Servicemanlist> lista = Servicemanlist.CreateServicemanlist();
foreach (var item in lista)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
break;
case 2:
{
List<string> lista = Serviceslist.CreateServicelist();
foreach (var item in lista)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
break;
case 3:
case 4:
{
Console.WriteLine("Bye, see you next time!");
done = true;
Console.ReadKey();
break;
}
}
}
}
}
}
}
我会有所帮助。
答案 0 :(得分:1)
您应该创建Priceofservices
类型的对象,并调用其方法SuperSwitch
Priceofservices pos = new Priceofservices();
pos.SuperSwitch();
或者您可以将SuperSwitch
设为static
,然后直接调用它而无需创建。
Priceofservices.SuperSwitch();
还向public
添加SuperSwitch
关键字以允许在类Priceofservices
之外进行访问