Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, 9 March 2015

ASSEMBLY IN .NET

Today in Engineer's World, we are discussing a very important topic of C# in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs


Assembly

An Assembly is a versionable unit of deployment of the .NET framework. Assemblies are the means of packaging and deploying applications and components in .NET. Assemblies can be made up of either single or multiple files. An assembly contains metadata information, which is used by the CLR for everything from type checking and security to actually invoking the components methods.



An assembly performs the following functions:

1. Assembly contains code that at run-time executes. MSIL code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest. Note that each assembly can have only one entry point.

2. Assembly forms a security boundary. An assembly contains several important pieces of information that can be used to decide what level of access to grant the component. An assembly is to .NET security what a protection domain is to Java security.

3. Assembly forms a type boundary. Every type's identity includes the name of the assembly in which it resides. A type MyTypeAssembly loaded in the scope of one assembly is not the same as a type MyTypeAssembly loaded in the scope of another assembly.

4. When you create a .NET application, you are actually creating an assembly, which contains a manifest that describes the assembly. This manifest data contains the assembly name, its versioning information, any assemblies referenced by this assembly and their versions, a listing of types in the assembly, security permissions, its product information (company, trademark, and so on), and any custom attribute.

5. Assembly forms a version boundary. The assembly is the smallest versionable unit in the CLR; all types and resources in the same assembly are versioned as a unit. The assembly's manifest describes the version dependencies you specify for any dependent assemblies.

6. Assembly forms a deployment unit. When an application starts, only the assemblies the application initially calls must be present. Other assemblies, such as localization resources or assemblies containing utility classes, can be retrieved on demand. In this way, applications can be kept simple and thin when first downloaded.

Assemblies can be static and dynamic. Static assemblies can include .NET Framework types (interfaces and classes) as well as resources for the assembly (bitmaps, JPEG files. resources files, and so on). Static assemblies are stored on disk in PE files. You can also use the .NET framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamics assemblies to disk after they have executed.

Some of the information used includes what site the component was downloaded from, what zone that site was in, (Internet, intranet, local machine, and so on) and the strong name of the assembly. The strong name refers to an encrypted identifier that uniquely defines the assembly and ensures that it has not been tampered with.
 
Code Cycle
 
There are several ways to create assemblies. You can use development tools, such as Visual Studio .NET. Visual Studio .NET, that you have used in the past to create .dll or .exe files. You can use tools provided in the .NET framework software Development Kit (SDK) to create assemblies by referencing modules created in other development environments. You can also use CLR application programming interfaces (APIs) to create dynamic assemblies.


For any query, comment us below.


Click imagination hunt to see latest Blogs

Keep learning and sharing...

Wednesday, 4 March 2015

How and Why .NET Namespace used?

Today in Engineer's World, we are discussing a very important topic of C# - Namespaces in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs


What is Namespace in C#?

A Namespace is collection of classes with related type contained in an assembly file. NET Framework provides namespaces with classes that can be used to code in various tasks. The .NET Framework class library can help you implement many tasks, including accessing databases, creating graphics, XML processing, networking, messaging, security, and directory services. Some commonly used namespaces during our initial start-up are listed below:
 
Namespaces in Asp.net
 
When referencing a class, one should specify either its fully qualified name, which means namespace followed by the class name, or add a using statement. This, eliminates the need to mention the complete name of all classes in that namespace.

/*You can write like this.*/
System.Console.WriteLine("Hello Engineer's!");
 /*Or, you can write like this.*/
using System; 
Console.WriteLine("Hello Engineer's!"); 

Before Proceeding, to learn various namespaces.
I encourage beginners to watch Basics of programming.

.NET Namespaces:

1. System: Contain the core classes. This namespace is used for following attribute like mathematical computations, Garbage collection, Intrinsic data, Exceptions and attributes.

using System;

namespace Engineer's_World
{
    class Namespaces
    {
        public static void Main()
        {
           
Console.WriteLine("Welcome to the Engineer's World!");
        }
    }
}

Output:
Welcome to the Engineer's World!

2. System.Collection: Contain collection classes and interfaces. This namespace is used when we are using collections (Generic and Non Generic), i.e., List, Stack, Queue, Hasttable, INumerable, ICollection, IDictionary.

3. System.Data: Classes for accessing Database. This Namespace is used when we are using Database connectivity in Ado.net Application. If any Namespace use "Data" attribute, then it will use for Database connectivity in .NET and may come under System.Data.

using System;
using System.Data;

namespace Engineer's_World
{
    class Namespaces
    {
        public static void Main()
        {
           
DataTable table = new DataTable();
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Type", typeof(string));

            // Here we add two DataRows.
            table.Rows.Add("Engineer's", "Profession");
            table.Rows.Add("World", "Education");
            Console.WriteLine(table.Rows[0].Field<string>(1));
        }
    }
}

Output:
Engineer's


4. System.Data.SqlClient: Classes for accessing Database. This also used for database connectivity in Ado.net. When we use SQL query for data connection.

using System;
using System.Data.SqlClient;

namespace Engineer's_World
{
    class Namespaces
    {
        public static void Main()
        {
             SqlConnection con = new SqlConnection(System.ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        con.Open();
       
SqlCommand cmd = new SqlCommand("select Username from UserLogin where Username='" + TextBoxU.Text + "' and Password='" + TextBoxP.Text + "'", con);

        }
    }

5. System.Configuration: When we configure some .net controls and use it in our .Net application. then we use this Namespace. Ex. Configuration of SQL Data Source or SQL Data Adapter and use it for connection.

using System;
using system.Data.SqlClient;
using System.Configuration;

namespace Engineer's_World
{
    class Namespaces
    {
        public static void Main()
        {
             SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        //con.Open();
        //SqlCommand cmd = new SqlCommand("select Username from UserLogin where Username='" + TextBoxU.Text + "' and Password='" + TextBoxP.Text + "'", con);
        }
    }
}
 


6. System.Windows.Forms: Classes for graphics and design of Windows Forms. When we are making any GUI based application in .NET then we use this namespace.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Engineer's_World
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void label1_Click(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.label1.Font = new Font("Arial", 12.0f);
            this.label1.Text = "Engineer's World";
        }
    }
}

7. System.Drawing: Classes for graphics and design of Windows Forms. This namespace is used for Graphical Primitive data type such as size, fonts and printing services etc.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Engineer's_World
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void label1_Click(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.label1.Font = new Font("Arial", 12.0f);
            this.label1.Text = "Engineer's World";
        }
    }
}


8. System.IO: Classes for disk Input/Output.

using System;
using System.IO;


namespace Engineer's_World
 {
    class Class1
    {
        public static void Main(String[] args)
        {
            using (
StreamWriter writer = new StreamWriter("D:\\out.txt"))
            {
                Console.SetOut(writer);
                Act();
            }
        }

        static void Act()
        {
            Console.WriteLine("This is Console.WriteLine");
            Console.WriteLine("Thanks for playing!");
        }
    }
}

9. System.Text: To process string in classes.

using System;
using System.Text;

namespace Engineer's_World
{
    class String_Builder
    {
        public static void Main()
        {
            /*Task- Replace and Remove method in StringBuilder*/
           
StringBuilder MyStr = new StringBuilder("Enginner's World!");
            Console.WriteLine("Initial Call:" + MyStr);
            MyStr.Replace("ne", "ee");
            Console.WriteLine("Call 2: " + MyStr);
            MyStr.Remove(5, 2);
            Console.WriteLine("Call 1: " + MyStr);
        }
    }
}


10. System.Threading: Thread support in .NET. This namespace is used when we are making a multi-threading application in .Net.

11. System.Xml: When we are using XML Language in our programs then we will use this Namespace in our programs.

using System;
using System.Text;
using System.Xml;


namespace Engineer's_World
{
    class String_Builder
    {
        public static void Main()
        {
            StringBuilder str = new StringBuilder();
            str.Append("<head>");
            str.Append("<name>Harry</name>");
            str.Append("<id>1</id>");
            str.Append("</head>");
            string Mystr = str.ToString();

            StringBuilder str1 = new StringBuilder();
            str1.Append("<head>");
            str1.Append("<name>Potter</name>");
            str1.Append("<id>2</id>");
            str1.Append("</head>");
            string Mystr1 = str1.ToString();

           
XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(Mystr);

           
XmlDocument xdoc1 = new XmlDocument();
            xdoc1.LoadXml(Mystr1);

            string name = xdoc.SelectSingleNode("head/name").InnerText;
            xdoc1.SelectSingleNode("head/name").InnerText = name;
            Mystr1 = xdoc1.OuterXml;
            Console.WriteLine(Mystr1);
        }
    }
}



[Note]: Most Important thing to keep in mind while using Namespaces. Usage will be done according to their requirement. Avoid unnecessary implementation of namespaces as it increases system overload.


For any query, comment us below.


Related Questions:


Q-1 Which of the following is NOT a namespace in the .NET Framework Class Library?
A) System.Process.
B) System.Security
C) System.Threading
D) System.Drawing
E) System.Xml
Ans. Option(A).

Q-2 Which of the following statments are the correct way to call the method Issue() defined in the code snippet given below? 

using System;
using System.Text.RegularExpressions;

namespace AspnetSolutions
{
  namespace College
   {
      namespace Lib
      {
         class Book
          {
              public void Issue()
              {
                  // Implementation code
              }
          }
          class Journal
          {
              public void Issue()
              {
                  // Implementation code
              }
          }
      }
   }
}

1. College.Lib.Book b= new College.Lib.Book();
    b.Issue();
2. Book b=new Book();
    B.Issue();
3. using College.Lib;
    Book b =new Book();
    b.Issue();
4. using College;
    Lib.Book b=new Lib.Book();
    b.Issue();
5.using Coleege.Lib.Book;
    Book b=newBook();
    b.Issue();
A) 1, 3
B) 2, 4
C) 3    
D) 4, 5
Ans. Option (A).

Q-3 Which of the followings are NOT a .NET namespace? 
1. System.Web;
2. System.Process;
3. System.Data;
4. System.Drawing2D;
5. System.Drawing3D;
A) 1, 3
B) 2, 4, 5
C) 3, 5
D) 1, 2, 3
Ans. Option (B).

Click imagination hunt to see latest Blogs

Keep learning and sharing...

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...