Dynamic Link Library (DLL)

Dynamic Link Library (DLL) is a module that contains methods and data that can be used by another module. In simple terms DLL file is used to make link between 2 files or sofwares. Inside visual studio we are having some templates that used to create .dll files. So far in the above articles we've done all our code inside Console App (.NET Framework) template. For the first time we going to use different template in visual studio called Class Library (.NET Framework). Open visual studio, click create new project, Now choose Class Library (.NET Framework) template.

Call by referrence or Reference type memory allocation

Class library (.NET Framework) template is not a executable template. Here we cannot compile the program like what we've done so far. Here we can only build the program. If we build the program a new .dll file will be generated inside bin - debug folder inside project's file location. Using that generated .dll file we can make a link between multiple projects. Once we create new project using class library template we'll not find any main method inside. we'll only find namespace with project name what we given.

CODE

EG 1 . Writing first DLL code.

namespace NewlyCreatedNamespace {
    public static class basicMath {
        public static double Deg2Rad(double degree) {
            return degree * Math.PI / 180;
        }
        public static double Rad2Deg(double radian) {
            return radian * 180 / Math.PI;
        }
    }
    namespace subNamespace1 {
        namespace space {
            public class rectangle {
                public double length, width, height;
                //Internal variable can only be accessed inside current class library project(It cannot be accessed outside this project).
                internal double sampleVariable;
                public double Area() {
                    return length * width;
                }
                public double Perimeter() {
                    return 2 * (length + width);
                }
                public double Volume() {
                    return Area() * height;
                }
            }
        }
    }
}



(Click Here, For more exercises)