Posts Tagged ‘C-Sharp’


The below method fetches the path for all the files present in a Directory or Sub Directory under the parent Directory.
The file path are fetched in a list of string to be used for any implementation as and when required.


private List DirSearch(string sDir)
{
List files = new List();
try
{
foreach (string f in Directory.GetFiles(sDir))
{
files.Add(f);
}
foreach (string d in Directory.GetDirectories(sDir))
{
files.AddRange(DirSearch(d));
}
}
catch (System.Exception excpt)
{
//throw ex
}

return files;
}


Below is the simple method that can be used to fetch file names of all the file present under a File Directory.


private static string[] GetFileNames(string path, string filter)
{
string[] files = Directory.GetFiles(path, filter);
for (int i = 0; i < files.Length; i++)
files[i] = Path.GetFileName(files[i]);
return files;
}

This code is designed in such a way so that we can obtain filename according to filetype.
If I provide ‘*.*’ as an input to filter, all the file names will be obtained in string array, but if I obtain ‘*.jpg’ as an input the string array will contain file names for all ‘.jpg’ files.

Example:

string[] fileNames = GetFileNames(@"C:\Users\Public\Pictures\Sample Pictures", "*.jpg");


This is a simple method that I created to build a string out of any object that is provided in the input in C#
This method is useful in order to log input and output object of any methods.
My requirement was to log the input object and output object for every method in the application. I created a generic method which enables the object properties and values to be builded as string and used to log in the log files.

The code for the same is provided below:
(more…)


Here is a simple method that returns the data in List object to be downloaded as an CSV file.

(more…)


Here are some questions for C# developers to prepare for there interviews.

(more…)

Converting Numbers to Words in C#

Posted: April 9, 2013 by Sagar Wasule in C-Sharp, Programming Concepts
Tags:

Introduction
A question which is often asked to programmers in interviews or comes up as in any of their development needs is – how do I convert a number to words?
In this article, I’d therefore like to present a simple program which is written to deal with this question for integers in the range of an Int32 (about plus or minus 2 billion) which I believe is the most useful case.
The program supports both the US and UK numbering systems. For example the number 620 would be expressed as follows:
    Six Hundred Twenty   (in the US system)
    Six Hundred and Twenty  (in the UK system)

Source Code

(more…)