首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在C# =>中执行控制台应用程序中的类库

在C# =>中执行控制台应用程序中的类库
EN

Stack Overflow用户
提问于 2018-08-15 03:21:10
回答 1查看 2.1K关注 0票数 0

我希望创建一个菜单驱动的程序,它将根据某些方面(例如操作符或任何其他东西)进行分类。

我已经创建了一个控制台应用程序项目,并以"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算术运算符,那么主要在类库中将包含加法、减法、乘法等。

EN

回答 1

Stack Overflow用户

发布于 2018-08-15 03:56:23

您需要添加对类库项目的引用。我假设你在相同的解决方案中创建了它们。确保这两个总线的目的相同。Net版本为4.6。要添加引用,请展开项目资源管理器,查找引用,右键单击,选择Add,然后找到类库并选中复选框。如果你安装了效率工具Resharper,那么修复这类问题的速度就会更快。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51848453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档