Wednesday, April 27, 2011

Property in Tutorial in C sharp

Property is Smart Method.
below given property example.

Tuesday, April 26, 2011

Indexer in Csharp Example

The Indexer is also known as Smart Array.
Benefit with Indexer is that we not need to define Limit Value like Array.
Example Of Indexer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Indexer
{
class Tutorial
{
string [] name=new string[15];
public string this[int range]
{
set { name[range] = value; }
get { return name[range]; }
}
static void Main(string[] args)
{
Tutorial p = new Tutorial();
p[0] = "Mike";
p[1] = "Milan";
p[2] = "Vihar";
p[3] = "Vivek";
p[4] = "Sharad";
Console.Write(" {0} \n {1} \n {2} \n {3} \n {4}",p[0],p[1],p[2],p[3],p[4]);


Console.ReadLine();

}
}

Monday, April 25, 2011

Exception handling Divide By Zero Exception

DivideByZeroException Exception Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exception handling 
{
    class Program
    {
        
        
        static void Main(string[] args)
        {
            int i;
            int j;
            int k;
            Console.WriteLine("Enter 1st No: ");
            i = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter 2nd No: ");
            j = int.Parse(Console.ReadLine());
            try
            {
                if (j == 0)
                {
                    throw new DivideByZeroException();
                }
                k = i / j;
                Console.WriteLine("Ans is " + k);
            }
            catch (DivideByZeroException)
            {
                    Console.WriteLine("Divide By Zero Not Possible..");
            
            }

            finally
            {
                Console.ReadLine();
            }
        }
    }
}