Understanding C Sharp Day 18
A class library defines types and methods that are called by an application.
The Class Library .DLL contains program code, data, and resources that can be can used by other programs and are easily implemented into other Visual Studio projects.
- Select C# in the language tab
- And then select Class Library (.NET Framework) and press the NEXT button
- You can then proceed to give your project a Project Name
- Call the project MathLibrary (in order to copy/paste example code)
- Press the CREATE button, After you have given a name to your project
The following code example is a C# version of the Class Library.
The Class Library .DLL contains program code, data, and resources.
The Class Library in this example will feature a custom Math API that has a set of functions to Substract, Devide and Multiply numbers.
Our Class Library project contains only of 1 file.
The Class1.cs file which is our API containing the methods to calculate simple mathematical operations.
The Class1.cs file is a C# class from our MathLibrary.dll that contains our methods to Substract, Multiply, Devide numbers.
- Substract() Method for subtracting 2 numbers.
- Multiply() Method for multiplying 2 numbers.
- Devide() Method for deviding 2 numbers.
- Power() Method for calculating the power a number.
Open VS 2019 and click on create new project tab.
Select Class Library(.NET Core) and press next button.
Give a project name and press create button.
Our class library has only one Class1.cs file which contains methods (like multiply) for API.
For converting source code into .dll file build your project.
Then open solution in file explorer to see whether the .dll file is generated or not.
- Create a new console application on clicking create new tab or you can right click on solution explorer tab and add new item.
- Select Console Application(.NET Core) and press next button.
- Give a project name and press create button.
- Add reference to project solution by right clicking on project and select add->add reference.
- Class1.cs file contains main method which serve as a entry point of application.
- To build your project, choose Build Solution from the Build menu.
- To run the code, on the menu bar, choose Debug - Start Debugging.
- A console window opens and then runs your app.
Comments
Post a Comment