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();
            }
        }
    }
}
 

Sunday, April 24, 2011

GridView Data Control in ASP.net Example

For ASP.net Beginner
ToolBox in that Data in that GridView Pick up and Drag that Control to ASPX page.
Which is Look Like This Image

Saturday, April 23, 2011

Exception Handling IndexOutOfRangeException

Exception handling for index outof range exception in c sharp.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ass_45
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] name = new int[3];
            Console.WriteLine("Enter Array Value:");
            try
            {
                for (int i = 0; i <= 3; i++)
                {

                    name[i] = Convert.ToInt32(Console.ReadLine());

                }
                for (int i = 0; i <= 3; i++)
                {
                    Console.WriteLine("Array" + name[i]);
                }
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Array Out of Index Ha Ha Ha");
            }
            finally
            {
                Console.ReadLine();
            }
        }
    }
}