Day 19 : Class Libraries in C#

 

In this blog we are going to understand the concept of class library and how to build a class library.

Class Library :

  • A class library is a collection of class definition contained in .dll or .exe file.
  • Both dll(Dynamic Link Library) and exe(Executable) files are executable program modules but the difference is that we cannot execute dll files directly.
  • The dll contains program code, data that can be used by other programs and easily implemented into other VS projects also.
  • In order to use class library we must add reference to the library.
Now we are going to understand how to build a class library :-

1) Build a class library :

  1. Open VS 2019 and click on create new project tab
  2. Select Class Library(.NET Core) and press next button.


  3. Give a project name and press create button.
  4. Our class library has only one Class1.cs file which contains methods (like multiply) for API.                                                                                                                                                                                                     
  5. 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.                                                    
                                                 

2) Use class library in other projects :

  1. Create a new console application on clicking create new tab or you can right click on solution explorer tab and add new item.
  2. Select Console Application(.NET Core) and press next button.
  3. Give a project name and press create button.
  4. Add reference to project solution by right clicking on project and select add->add reference.
  5. Program.cs file contains main method which serve as a entry point of application.

3) Run project :

  1. Firstly you should build your project by clicking build solution in build menu.
  2. To run the code, choose debug option from menu bar. 

Thank You!!!

For more understanding watch below video :

Comments

Popular posts from this blog

Day 3 : JavaScript

SQL Concepts-1

ASP .NET Session Management