Monday, February 8, 2010

Input/Output (I/O)

File System Class

this file system class are inside the system.IO namespace. it use to manipulate and navigate file, directories and drivers. those class can be categorized in to two type of class file system info and utility.
C# code for get file system information
FileInfo fl = new FileInfo("C:/setup.log");
if (fl.Exists)
{
Console.WriteLine("file Name " + fl.FullName);
}

Enumerate file in directory
DirectoryInfo df = new DirectoryInfo("C:/");
foreach( FileInfo file in df.GetFiles())
{
Console.WriteLine("file Name " + file.FullName);
}
fleSystemwatcher class is used to monitoring file system in the specific path,and can be register event and monitor file changes information.

C# Framework Fundamentals

1. Common Reference Type
i) String and String Builder
Strings are immutable, which mean in the run time it will create the new string and abundant the old one,
ex :-
String s = new String();
s+="string1";
s+="string2";

string Builder class is mutable it will create at dynamicaly and we can defined its length what ever we want.
ex :- System.Text.StringBuilder sb = new System.Text.StringBuilder(30);
sb.Append("string1");
sb.Append("string2 ");
string s = sb.Tostring();


Generics
reduced runtime error,
improve runtime performance

example : OBject class without Genarics :-

Class Object (){
public Object t;
public object u;
public object(object t1, object u1){
t = t1;
u = u1; }
}
add two string to object class
Object obj = new Object("string1","string2");
console.writeline((string)obj.t + (string)obj.U);

the above way can be used using genarics
class gen
{
public T t;
public U u;
public gen(T t1, U u1){
t =t1;
u = U1;}
}

add two string to Gen class
Gen gen = new Gen("string1","string2");
console.writeline(gen.t + gen.U);
//above methode no need to object cast , also it does not occur runtime error, (int double cast error);

Introduction

Let's start to share C# knowledge