Category Archives: C#.NET

Get characters in a string – C Sharp/C#

By | April 7, 2012

Hi, Sometimes you may need to get all the characters in a string using C Sharp/C#. The following code gives you an example of how to get or display all the characters of a given string. Output: sampleString[0] = I sampleString[1] = sampleString[2] = L sampleString[3] = o sampleString[4] = v sampleString[5] = e sampleString[6]โ€ฆ Read More »

Sort elements in a String Array – C Sharp / C#

By | June 21, 2011

Hi, In order to sort the elements in a string array in C Sharp/C#, we use the sort() method. Given below is a simple example using sort() method to sort the elements in a string array. It will print out, Sorted string Array: urStringArray[0] = apple urStringArray[1] = coderz urStringArray[2] = heaven123 urStringArray[3] = heaven777โ€ฆ Read More »

C Sharp/C# – String Uppercase/Lowercase Conversion

By | April 28, 2011

Hi, It will be very useful to know how you can convert a given string into uppercase or lowercase using program. We are going to show you , how to convert a given string into uppercase or lowercase using C Sharp/C#. See the example given below. Output : Lowercase of sampleString : coderzheaven Uppercase ofโ€ฆ Read More »

Program to generate Fibonacci series in C Sharp/C#

By | April 27, 2011

Hi, Here is a simple program to generate Fibonacci series using C Sharp /C#. It will generate Fibonacci numbers < 100. [csharp] class MainClass { public static void Main() { int oldNum = 1; int presentNum = 1; int nextNum; System.Console.Write(presentNum + ","); while (presentNum < 100) { System.Console.Write(presentNum + ","); nextNum = presentNum +โ€ฆ Read More »

Get files from a directory – C#/C Sharp

By | April 25, 2011

Hi, Sometimes you may need to get the files from a specified directory using C# / C Sharp. See the sample code on how it works. using System; using System.IO; class MainClass { public static void Main() { string[] yourFiles = Directory.GetFiles("c:"); foreach (string fNames in yourFiles) Console.WriteLine(fNames); } } This code will get youโ€ฆ Read More »

C#/C Sharp – Delete file in a folder

By | April 25, 2011

Hi, Let’s see a simple example of deleting a file in a folder using c#. using System; using System.IO; public class MainClass { static void Main(string[] args) { FileInfo sampleFile= new FileInfo(@"c:SamplestestFile.txt"); sampleFile.Create(); sampleFile.Delete(); } } sampleFile.Create() will create the file in the specified folder. sampleFile.Delete() will delete the file in the specified folder. ๐Ÿ™‚

How to create a text file in C# ?

By | April 23, 2011

Hi, How can you create a text file in C# and write to it? Sometimes you may need to create a text file using C sharp program. Here is how you can do that. using System; using System.IO; class MainClass { static void Main(string[] args) { StreamWriter yourStream= null; string yourString= "I Love Coderz Heaven!";โ€ฆ Read More »

A simple exception handling using C#

By | April 23, 2011

Hi, See how a very simple exception handling works with try-catch methods using C#. using System; class MainClass{ public static void Main(){ int divOne = 0; try { int ans = 79 / divOne ; } catch (Exception e) { Console.WriteLine("You got the exception-> " + e.Message); } } } Output- “You got the exception->โ€ฆ Read More »

How to find a leap year using C# ?

By | April 18, 2011

Hi, Sometimes you may need to find whether a particular year is leap year or not. But how can you find out whether a particular year is leap year or not in C# ? Use the following code. using System; class MainClass { public static void Main() { bool myResult= DateTime.IsLeapYear(2011); Console.WriteLine("Is the year 2011โ€ฆ Read More »