.Net is a manage type safe environment for development and execution of software..Net framework allow us to memory allocation , storage and grant permission on software ..Net component can interact with each other , it does not matter , it is written in C# ,Vb.Net or else .This feature is possible for MSIL or Microsoft Intermediate Library .When a source code is compiled , complier convert the source code to Il or Inter mediate language , MSIL include loading ,storing ,initialization and calling method. We can view IL generated code by ILSAM.exe , Intermediate Language disassembly , which is present in .Net sdk folder.
Another component of .Net is JIT , which convert MSIL code to machine code or CPU instruction during runtime.
The CTS ensure the type compatibility between .Net component . CTS defines the predefined data type that are available in IL , so that all language target the .NET framework will produce the compiled code that is ultimately based on these types..Net source code can be written in C#,Vb.Net etc , but after MSIL compilation both will be same type as guaranteed by CTS . For Example Visual Basic Interger and C# will both represent as Syste.Int32.
But when we are going to understand .Net architecture , we need to know assemble .Assembly also a compiled code for deployment , it is self describing and has collection of metadata .An assembly contain
- IL- Intermediate Language
- Metadata-data about data
- Manifest-Information about version.
Now what actually happen when a .Net program executed , When a Program executed , the assembly is the first loaded into memory .Now CLR examine the requirement to run the program .Then CRL create a process for the application .The JIT just convert the MSIL code to CPU instruction and loaded into memory as native code.
System : Responsible for fundamentals of programming such as the data types, console, match and arrays, loop ,event hadling
System.Data : Responsible for ADO.NET feature , dataaset , datatable,datareader ect.
System.Drawing : Responsible for the GDI+ functionality for graphics support
System.IO: Responsible for file system and the reading and writing to data streams such as files.
System.Net: Responsible for network protocols such as SSL, HTTP, SMTP and FTP
System.Text: Responsible for StringBuilder class, plus regular expression capabilities.
System.Web: Namespace for ASP.NET capabilities such as Web Services and browser communication.
System.Windows.Forms: Namespace containing the interface into the Windows API for the creation of Windows Forms programs.
Value Type & Reference Type
Application memory is mainly divided into two memory
component . Heap and Stack .
Heap is a separate area of memory for holding reusable
objects .Actual object is allocated in Heap .A variable containing pointer to
an object is allocated on stack , when call by stack actually return the memory
address of the objects.
Value Type : Int/Bool/Struct /Enum
Reference Type :Class/array/interface/delegate
Value Type
- Value Type are stored on stack
- Value Type contains actual value
- Value Type cannot contain null values.
- Value type is popped on its own from stack when they go out of scope.
- For Value Type Memory is allocated at compile time
Reference Type
- Reference Type are stored on heap
- Reference Type contains reference to a value
- Reference Type can contain null values.
- Reference Type required garbage collector to free memory.
- Reference Type memory is allocated at run time
Stack
- very fast access
- local variables only
- variables cannot be resized
- It is a Last-in, First-out (LIFO) data structure
- Static memory allocation
Heap
- No limit on memory size
- Variables can be resized
- Fist in First Out
- Dynamic memory allocation
Example of Stack
int a=100;
string ="C# program”;
int a=5+6;
Exaple of Heap
{
int myInt = 0;
string myString = "Something";
}
class Program
{
static void Main(string[] args)
{
MyClass m = new MyClass();
}
}
Namespaces
Namespaces are a logical grouping , it is not connected with physical file or code ect. Namespaces are generally structured as hierarchies to use & reuse of names in different contexts . In Microsoft .Net ,a namespace is an abstract container providing context for the items . When we write program , it is created with a default namespace. This default namespace is called as global namespace. But the program has capability of declare any number of namespaces in it also , but it should be a unique name. The result is that every namespace can contain any number of classes, functions, variables and also namespaces etc., whose names are unique only inside the namespace.
In C# , we can define
namespace namespace_name
{
// code
}
For example I am writing names space student , and declaring object in it
namespace student
{
class student_info
{
name string;
roll int;
}
}
Now I , can create instance of class “student_info” ,like
student.student_info
sc = new student. student_info();
namespace class
{
class class_info
{
class_name string;
no_of_student int;
class_teacher_name string;
}
}
Now at the top , we should write
using System;
using classes;
Now class under namespace “classes” , will be easily available .We ca use
class_info c1=new
class_info();
Namespaces allow you to create a systematic organized code via hierarchical system.
A good code should put the general name at the top of the hierarchy and more specific
As get down.
For example “System” is the highest level of namespace hierarchy, “using System” will allow you some general coding , standard library etc.
System.Data, System.Net comes under “System” names space .” System.Data” will allow you to access data adopter, dataset,data reader ect. ” System.Net” for some netword component.Please see the below example
namespace Level1Hierchy
{
class MyClass1
{
//defination of the class
}
namespace Level2Hierchy
{
// Program start class
class MyClass2
{
//defination of the class
}
}
}
“Level1Hierchy” is the top level namespace , “Level2Hierchy” is under Level1Hierchy.
“MyClass2” is defined under “Level2Hierchy” , we need to write code to access
Level1Hierchy.Level2Hierchy.MyClass2 obj1 = new Level1Hierchy.Level2Hierchy.MyClass2();
But “MyClass1” is defined under “Level1Hierchy” , we can access by
Level1Hierchy.MyClass1 obj2 = new Level1Hierchy.MyClass1();
“MyClass2” is defined under “Level2Hierchy” , we need to write code to access
Level1Hierchy.Level2Hierchy.MyClass2 obj1 = new Level1Hierchy.Level2Hierchy.MyClass2();
But “MyClass1” is defined under “Level1Hierchy” , we can access by
Level1Hierchy.MyClass1 obj2 = new Level1Hierchy.MyClass1();
No comments:
Post a Comment