Tag Archives: Csharp

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 »

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 »

Accessing all items of an Array in C#

By | April 18, 2011

Hi, In order to access all the items of an array in C#, use the following lines of code. We are using foreach loop to access all the elements of an array in C#. using System; class MainClass { public static void Main() { string myString = "Apple Ball Cat"; char[] separator = {‘ ‘};… Read More »