Thursday 31 March 2011

Variables and its Data Types


In practical life nobody can carry each and every file, folders or documents with himself except of those which he uses them very frequently or is very important but for those who are not important he need any place like drawer or cabinets to store them and can reuse them whenever he needs. In the same way .Net framework also need any place to store things and can reuse them, these places are called Variables. Variable store values of some specific type and these types are called Data Type. There are various types of data type like integer, float or string.

In order to store any numeric value .Net gives us various types like byte, sbyte, short, ushort, int, uint, long, ulong, float, double from which only float and double can carry decimal values and rest of them can only carry whole number. There are different ranges of maximum and minimum values for different types that they can hold. These ranges depends on the spaces (in bytes) occupied by variables of specific type in the memory.

Byte and sbyte occupies one byte in the memory and it ranges from 0 to 255 and -128 to 127 respectively. The only difference between byte and sbyte is that byte can not carry signed values and sbyte can.

27
26
25
24
23
22
21
20
                     Byte

Short and ushort occupies two bytes in the memory and it ranges from -32768 to 32767 and 0 to 65535 respectively. The only difference between short and ushort is that short can carry signed values and ushort can not.

27
26
25
24
23
22
21
20
215
214
213
212
211
210
29
28
                     Short

Int and uint occupies four bytes in the memory and it ranges from -2147483648 to -2147483648 and 0 to 4294967295 respectively. The only difference between int and uint is that int can carry signed values and uint can not.

27
26
25
24
23
22
21
20
215
214
213
212
211
210
29
28
223
222
221
220
219
218
217
216
231
230
229
228
227
226
225
224
                     Int

Table given below give the list ranges and bytes occupied by the variable of different type:

Data Type
Size in Bytes
Minimum Range
Maximum Range
sbyte
1
-128
127
byte
1
0
255
short
2
-32768
32767
ushort
2
0
65535
int
4
-2147483648
2147483647
uint
4
0
4294967295
long
8
-9223372036854775808
9223372036854775807
ulong
8
0
18446744073709551615
double
8
-1.79769313486232E+308
1.79769313486232E+308
decimal
16
-79228162514264337593543950335
79228162514264337593543950335

In the same way .Net also gives string data type to store alphanumeric data. String occupies 20 plus bytes means initially it occupies 20 bytes but when maximum value of its range reaches it will increases its bytes. If we store numeric value in string type it will not consider it as numeric, it will be considered as string (but .Net gives various methods to convert string in integer and other numeric value types).

Monday 28 March 2011

.NET FRAMEWORK AND ITS ARCHITECTURE


.NET FRAMEWORK AND ITS ARCHITECTURE:

Before going to explore what .Net Framework is? We need to understand actually what the framework is? Framework as define on dictionary.reference.com/ that:

“Framework is a skeletal structure designed to support or enclose something.”

In general, a framework is a supporting structure for building the desired projects by using the tools and resources provided by the framework. In computer science framework is a set functions or classes and by using these functions or classes we can build our complex applications.

.Net Framework support the designing of next generation applications from as simple as Console Application to as complex as windows form Application, web application, windows phone 7 applications and etc. It provides the flexibility for the programmer to design his code in more than 30 languages. In .Net Framework one can create an application or library in one of the language supported by .Net Framework and can use it on program written on another language. .Net Framework is basically consists of two major components 1) Common Language Runtime (CLR) 2) Frame Class Library (FCL). This is also illustrated in the figure bellow:



Common Language Runtime in .Net Framework is responsible of the execution of .Net code and it provides several useful services such as memory management, thread management, Exception handling, Garbage Collection, Security and etc. The code compiled from C sharp compiler or other language compiler is in Microsoft Intermediate language which is not understandable to operating system, So CLR runs the Just in Time Compiler (JIT) to convert the MSIL to machine native language which can be executed. So in other word CLR communicates with the OS for execution of .Net code. In this way our program does not need to communicate with OS.

Framework Class Library in .Net Framework contains a huge collection useful and reusable classes which we can use them in our project to build complex applications very easily. In other word FCL gives us flexibility to implement the functions in just single line which needs a large number of Line of Code (LOC) for the implementation in the previous or other languages. As shown in the figure FCL is also divided in major chunks such Base Class Library (BCL), ADO.Net, Web Services and etc. BCL contains all those libraries that are common to all languages which can be used in .Net Framework. ADO.Net contains the libraries related to accessing the databases. Web Services contains the libraries related to the development of web based applications.

Common Language Specification is agreement among languages those are support by .Net Framework that every language must contain some common subset which is defined in CLS. You can also create your own language and make it supported by .Net Framework by including those common subsets. CLS provides the basic rules that are requires for language integration.