USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
Namespaces in C#
1. Namespaces
The class library organizes its classes into namespaces.
For ex: .Net Framework,Jscript,C#,Win32 etc.
Namespaces helps to create logical groups of related
classes & Interfaces that can be used by any language
target by .Net framework.
Namespaces helps us to organize our classes so that
they can be easily accessed by any other application.
Namespaces are use to avoid conflicts between classes
that have same names. For ex: We can use two classes
with same names but with different namespaces.
We can access namespace by simply importing the
namespace into application.
2. Net uses (.) operator as a delimeter between class &
namespace
A namespace definition begins with the
keyword namespace followed by the namespace
name as follows:
namespace namespace_name
{
code declarations
}
3. using System;
namespace first_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside first_space");
} } }
namespace second_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside second_space");
} } }
class TestClass
{
static void Main(string[] args)
{
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.func();
sc.func(); Console.ReadKey(); } }
4. The using Keyword
The using keyword states that the program is using the
names in the given namespace. For example, we are
using the System namespace in our programs. The class
Console is defined there. We just write:
Console.WriteLine ("Hello there");
5. Few Namespaces & their description
Namespaces Description
System Include essential classes & base classes
for commonly use datatype, events & so
on
System.Windows.Forms.Form Include classes needed to create
Window form.
System.Windows.Forms.Button Include classes needed for using
button.
System.Data Include classes that make up ADO.NET
System.SqlClient Include classes that support SQL server
.Net provider.
System.XML Include classes that support XML.
System.Web Provides Classes & Interface that
support browser server communication.
System.Net Provides Interface to protocols used on
Internet
6. Assembly
The namespace are placed within Assemblies.
Assemblies are the building blocks of .Net application,
the common language runtime does not support types
outside of assemblies.
Assembly files are located on somewhere on the disc
that are defined as Portable Executable(PE).
An Assembly is a single deployable unit that contains
the all information about the implementation of classes,
structure & Interface.
An Assembly stores all information about itself.
Dot NET assemblies may or may not be executable, i.e.,
they might exist as the executable (.exe) file or dynamic
link library (DLL) file.
7. Assembly & metadata provides the CLR with the
information required for executing the application.
For ex. If an application uses a component the assembly
keeps tracks of version no of component used in
application.
The Assembly provides the information to the CLR
while application being executed.
8. Components of Assembly
Assembly consist of Manifest, Module & Type
Manifest describe the Manifest. It contains..
Name & version no of assembly
Its Interaction information with other assemblies.
Security permission required by the assembly
Module is either a DLL & EXE file. It contains..
Compiled code or Intermediate language code
Metadata associated with module.
Type is a class that contains data & logic affecting
the data.
9. Functions of Assembly
An assembly in .Net framework performs following
functions..
Support Execution
Provide security
Provide unique identification
Track version
Support Deployment
Support side by side execution
10. Private Assembly and a Shared Assembly
Private assembly can be used by only one
application.
Private assembly will be stored in the specific
application's directory or sub-directory.
There is no other name for private assembly. Private
assembly doesn't have any version constraint.
11. Public Assembly:
Public assembly can be used by multiple applications.
Public assembly is stored in GAC (Global Assembly
Cache).
Public assembly is also termed as shared assembly.
Public assembly should strictly enforce
12. Compiler:
When you compile a program developed in a
language that targeted the CLR instead of compiling
the source code into machine level code , the
compiler translate the source code into Microsoft
Intermediate Language or IL. This ensures language
interoperability.
The compiler also produces metadata about the
program during the process of compilation.
The process of compiling & executing the
managed code is given below..
13. Metadata contains the description of the program such
as the classes & interface, the dependencies & the
version of component used in the program.
Class loader:
When we execute the .EXE & .DLL file the code & all
other information from the base class library is sent to
the class loader.
The class loader loads the code into memory.
14. Before the code can be executed ,the .Net framework
needs to convert the IL into native or CPU specific code.
The just In time compiler translate the code from IL
into manage native code.
The CLR supplies a JIT compiler for each supported
CPU architecture.
During the process of compilation the JIT compiler
compiles the code that is required during execution
instead of compiling the complete IL code
When an uncompiled method is invoke during
execution the JIT compiler converts the IL for that
method into native code
JIT Compiler
15. This process saves the time & memory required to
convert the complete IL into native code
During JIT compilation the code is also checked for type
safely.
Type safely ensures the objects are always accessed in a
compactable way.
Type safely also ensures that objects are safely isolated
from each other & are therefore safe from any
corruption.