我希望创建一个菜单驱动的程序,它将根据某些方面(例如操作符或任何其他东西)进行分类。
我已经创建了一个控制台应用程序项目,并以"sample“作为命名空间。在示例中,我在Main()中创建了一个菜单。
public static void Main()
{
Console.Clear();
Console.WriteLine("\nMenu Driven Program");
Console.WriteLine("\n<--------List of Available Options-------->");
//Creating a list to Select from
Console.WriteLine("\n Select Any of the Following Function :");
Console.WriteLine("\n_________________________________________");
Console.WriteLine("\n1. Arithmatic Operators\n2. Logical Operators");
Console.WriteLine("\n3.Misc1\n4. Misc2");
//Accepting a normal string
string b = Console.ReadLine();
int d;
// Following converts string into an integer
Int32.TryParse(b, out d);
//Following code is used to create menu-driven program
switch (d)
{
case 1:
//Here I wish to call one class library
break;
case 2:
//Here I wish to call another class library
break;
//And so on.
default:
Console.WriteLine("\n\nWhat you wish to do?\na. Continue the Program\n\nb. Exit the Program");
char c = Convert.ToChar(Console.ReadLine());
if(c=='a'||c=='A')
{
Main();
}
else
{
Exit();
}
break;
}
}
现在,我创建了一个类库,我将在其中存储三个类(让我们考虑一下):增量、除法和乘法。
但是,我无法调用该类库。当我在开关"Case“中直接输入类库的名称时,它给出了CS0118错误,说明"Sample”只是一个名称空间,但使用起来像变量。
在我的类库中,我创建了三个不同的类,并再次创建了Main(),它将显示可用操作的列表。Eg.If算术运算符,那么主要在类库中将包含加法、减法、乘法等。
发布于 2018-08-15 03:56:23
您需要添加对类库项目的引用。我假设你在相同的解决方案中创建了它们。确保这两个总线的目的相同。Net版本为4.6。要添加引用,请展开项目资源管理器,查找引用,右键单击,选择Add,然后找到类库并选中复选框。如果你安装了效率工具Resharper,那么修复这类问题的速度就会更快。
https://stackoverflow.com/questions/51848453
复制相似问题