Assemblies in C#

Working with assemblies:

1)A collection of classes is called as a namespace

2)A collection of namespaces is called as an assembly

3)A collection of assemblies is called as FCL(Framework class library) (or) BCL

4)A dll file is called as an assembly

5)To add an assembly into the project

    Goto project menu->add reference->.Net(or) browse->select a Dll file

6)Assemblies are reusable

7)Assemblies contains only reusable logic but not design

8)Assemblies supports lang interoperability i.e the assembly developed in C#, .Net can be used from any another .Net program language including asp.net

9)To develop assemblies, we required “class library project template

10)Assemblies are not executable, These are only reusable

11)Assemblies are divided into 3 types

a)private assemblies

b)shared assemblies

c)sattilite assemblies…required while working with globalization

 

12)The referred private assembly dlls will be copied automatically into current projects debug folder. In case of shared assemblies the dlls will not be copied

13)Private assemblies are faster in accessing and shared assemblies are memory wise more efficient

14)When ever only one project need to be developed for one client, Then recommended to use private assemblies

15)When ever more than one project need to be developed for same client, Then recommended to use shared assemblies

16)Using keyword loads the classes of only last specified namespace

 

Example on private assembly with multiple namespaces 

Open class library project with project name pa:

Start->programs->Microsoft visual studio 2010->Microsoft Visual studio 2010->file menu->new->

project->select visual c# from installed templates->select class library template

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace pa

{

    public class paclass

    {

        public string pamethod()

        {

            return "form pamethod of paclass";

        }

    }

 

    namespace sa // need to used as pa.sa

    {

        public class saclass

        {

            public string samethod()

            {

                return "from samethod of saclass";

            }

        }

    }

}

 

Note: for every project by default a namespace will be created with the same name as project name

 

Steps for providing meta data:

Goto project menu->pa properties->application->click on “assembly information” button then provide the data as follows

Title: product management system

Description: having 2 namespaces, 2 classes and 2 methods

Company: perrs tech

Product: pms

Copy right: all the rights are reserved to u and me

Click on ok

 

Build the project

Goto build menu->build solution (or) build pa

 

Note: then pa.dll is created under drive\foldername\pa\bin\debug folder, which is by default private assembly

 

Steps to reuse pa.dll private assembly

Open windows forms application project:

Start->programs->Microsoft visual studio 2010->Microsoft Visual studio 2010->file menu->new->

project->select visual c# from installed templates->select windows forms application project 

 

The project name patest

Place a button

Goto project menu->add reference->browse->pa.dll

Use two name spaces

 

using pa;

using pa.sa;

 

Code for button1_click

{

  // to use the classes and methods etc..

  Paclass p=new paclass();

 Messagebox.show(p.pamethod());

 Saclass s=new saclass();

 Messagebox.show(s.samethod());

}

 

Goto F5