Tuesday, February 4, 2014

Is Operator in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IsOperatorSample
{
    public class Animal
    {
    }

    public class Vehicle
    {
    }

    public class Car : Vehicle
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            Vehicle v = new Vehicle();
            Animal a = new Animal();
            Car c = new Car();

            if (c is Vehicle)
            {
                Vehicle newV = (Vehicle)c;
                Console.WriteLine(c.ToString() + " is a Vehicle. ");
            }
            else
            {
                Console.WriteLine(c.ToString() + " is NOT a Vehicle. ");
            }


         
         
     

            Console.ReadLine();
        }
    }
}

0 comments:

Post a Comment