

That's because CalculatorLibrary is in a different namespace. Program.cs also has a reference, but an error says that the Calculator.DoOperation call doesn't resolve. Return text for an incorrect option entry. Ask the user to enter a non-zero divisor. Use a switch statement to do the math. Public static double DoOperation(double num1, double num2, string op)ĭouble result = double.NaN // Default value is "not-a-number" if an operation, such as division, could result in an error.
#Prompt user console app visual studio code#
Then, in CalculatorLibrary.cs, paste the code into the CalculatorLibrary namespace.Īlso add public before the Calculator class to expose it outside the library.ĬalculatorLibrary.cs should now resemble the following code: using System In Program.cs, select the Calculator class and all its code, and press Ctrl+ X to cut it. The project reference appears under a Projects node in Solution Explorer. In the Reference Manager dialog box, select the checkbox for the CalculatorLibrary project, and then select OK. In this dialog box, you can add references to other projects, assemblies, and COM DLLs that your projects need. The Reference Manager dialog box appears. Right-click the Dependencies node in the Calculator project and choose Add Project Reference. Now add a project reference, so the first project can use APIs that the new class library exposes. It doesn't matter how you answer, because you'll replace the code in a future step. To rename the file, you can right-click the name in Solution Explorer and choose Rename, select the name and press F2, or select the name and click again to type.Ī message might ask whether you want to rename references to Class1 in the file. Rename the Class1.cs file to CalculatorLibrary.cs. Visual Studio creates the new project and adds it to the solution. On the Configure your new project screen, type the project name CalculatorLibrary, and then select Next.Ĭhoose. Choose the C# Class library project template, and then select Next. In the Add a new project window, type class library in the Search box. In Solution Explorer, right-click the solution node and choose Add > New Project.
