Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, February 16, 2011

var datatype in C#

Declaring local variables implicitly has some restrictions; the variable must be initialized to some expression that can not be null.

var a= 10;
var z = "Rekha";

The primary reason for its existence is the introduction of anonymous types in C#

Another point to stress is that variable inference does not work for class level fields or method arguments or anywhere else other than for local variables in a method.

Advantages :

Less typing with no loss of functionality

Increases the type safety of your code. A foreach loop using an iteration variable which is typed to var will catch silently casts that are introduced with explicit types

Makes it so you don't have to write the same name twice in a variable declaration.

Some features, such as declaring a strongly typed anonymous type local variable, require the use of var

What is difference between Physical path and Virtual path?

Physical path is the path where ur original application has
stored(actual directory path of application).

virtual path is the link between physical path and
IIS..becoz to execute the webapplication in Physical
path,it needs to be mapped on to IIS(webserver) and this
logical link between physical path and IIS is called
virtual path

Recursive method for Find all directory and inside the directory found all files

// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
//Logic here in file
}

// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries){
ProcessFile(fileName);
}


// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
{
ProcessDirectory(subdirectory);

}
}

//call the Method

string FilePath = Request.PhysicalApplicationPath + "UploadFile";
if (Directory.Exists(FilePath))
{
ProcessDirectory(FilePath);

}