Home > DeveloperSection > Forums > Can anyone explain about dll.
Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    September-22-2016 6:19 AM

 C# C# 
Ratings:


 1 Reply(s)
 411  View(s)
Rate this:
Hi Buddy

I am working with dll project can you  explain what is the use of  it with help of program.
I would really appreciate your help

Thanks


Abhishek Srivasatava
Abhishek Srivasatava

Total Post:24

Points:168
Posted on    September-22-2016 7:14 AM

Hi Samuel,

DLL is a library which may contain code, data or other information that can be accessed by other program at the same time.

DLL full form is Dynamic link library.

It is of two types:

Static link: If it is used, then DLL file will be use till the program is Active.

Dynamic link: If it is used then DLL file will be used when it is required.

 

DLL Advantage:

 

* Reduces the duplication of code which is loaded on the disk and in physical memory.

Explanation : As multiple program which contain same DLL executing in the memory, then single DLL is required for the multiple program. 

 

* Easy Updates and installation:

Explanation : When there is some improvement or update in the DLL file then update is not required for all the program only update is required.

Here is the small program to explain concept of dll:

Please follow these step :

* Open the New project , select class Library.


Now write your program 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ClassLibrary1
{
    public class Class1
    {
        public int adding(int a, int b)
        {
            return a + b;
        }
        public int subtract(int a, int b)
        {
            return a - b;
        }
        public int multi(int a, int b)
        {
            return a * b;
        }
        public int divi(int a, int b)
        {
            return a / b;
        }
    }
}

 
Save your code and then Press F6 or click on build on menu bar, under build click on build solution
Check dll file will build , under bin -->debug--> dll file.

Now, open the console application and write your code :
Note : Before running your code you need to add the class library to the console program
For this you need to open Solution Explorer present under View button. 
Under solution explorer, right click on the name of name of the program , click on add reference , new window will be open click on browse button0 and add the dll file. 
And at last click on StartUp project. And then execute your program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary1;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 obj = new Class1();
            Console.WriteLine("Enter the 1st number");
            int num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the 2nd number");
            int num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Addition of two num: \nresult= {0}\nSubtraction of two num:\nresult= {1}\nmultiplication of two num:\nresult={2} ", obj.adding(num1, num2), obj.subtract(num1,num2),obj.multi(num1,num2));
            if (num2 == 0)
            {
                Console.WriteLine("Division is not possible");
            }
            else
            {
                Console.WriteLine("Division of two num is:\nresult={0}", obj.divi(num1, num2));
            }
            Console.ReadLine();
        }
    }
}






Modified On Sep-22-2016 07:14:54 AM

Don't want to miss updates? Please click the below button!

Follow MindStick