Following are some of the basic facts and
tidbits in the .NET framework which we come across very frequently while writing
applications. The following article would be more of a use to the beginners in
.NET
Types in .NET :
The following types have been actually implemented as STRUCTS in .NET framework
- bool
- int
- boolean
- byte
- char
- float
- decimal
- datetime
- double
The below given types have been implemented as
CLASSES in the .NET framework
The “int” that we define is “System.Int32”.
‘int' is an alias for System.Int32 and similarly other data types also have
their own aliases. So the below declarations are identical
Int i = 0; is same as
System.Int32 i = 0;
Boolean and Bool are identical and any one of them can be used. Boolean is the
actual type and ‘bool' is just an alias for Boolean
Console Class :
The console class which is extensively used in console applications is a static
class which facilitates basic input,output streams from the console. We can
input and output data in console applications with the help of console class.
TextReader
a = Console.In;
TextWriter
b = Console.Out;
string
str = a.ReadLine();
b.WriteLine(str);
Convert Class :
This is again a static class. We can convert an object of one data type to
another using the Convert class, provided the conversion is allowed. Suppose we
want to convert some object into a string, we can use Convert.ToString();
method.
Type Convert.ToString( and we can check for the overloads of the methods whether
our object can be provided as an input to this method to convert it to string.
Directory, DirectoryInfo, File, FileInfo : These classes can be used to work
with the file system on the local or a remote computer.
Some_Object.Equals() method can be used to check for the equality between the
objects. The method returns a Boolean value.
Math Class :
Static class MATH provides us with utility functions that can be directly used
for mathematical operations.
Eg Math.Max(number1,number2) – returns us the maximum of the two numbers. There
are several other functions in Math class. You can go through them by typing
“Math.”.
Creating new GUID :
We can create a new Guid programmatically
Guid
newGuid = Guid.NewGuid();
Console.WriteLine(newGuid);
String and stringbuilder classes let us work with strings in .NET framework. The
String is an immutable object.
Suppose we concatenate two strings str1 and str2 using “str1+str2” statement.
Here the str2 in NOT simply added to the str1 object. Instead the concatenation
is done in a new object and the existing objects are destroyed. This becomes a
costly operation if there are a lot of concatenations involved in the program.
StringBuilder is a mutable string. We can use the ‘Append' method on a string
builder object to concatenate strings. This does not create a new object for
concatenated string but it simply adds the string ahead of the existing object.