stackoverflow1453

Programming&&Games&&Life

is, as operators

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

namespace _08_06_2017_a
{
    class Person
    {
        public int age = 25;
        public string Name = "Anonymous";

    }
    class Employee : Person { }

    class Program
    {
        static void Main(string[] args)
        {
            Person p1 = new Person();
            Employee Mahmut = new Employee();
            Employee e;

            Person p;
            //Check if variable can be converted to type Person
            if (Mahmut is Person)
            {
                e = Mahmut;
                Console.WriteLine("{0}, {1}", e.age, e.Name);
            }

            p = Mahmut as Person; //p=(Person)Mahmut

            if (p != null)
            {
                Console.WriteLine("{0}, {1}", p.age, p.Name);
            }
            Console.ReadKey();
        }
    }
}
Advertisements

No comments yet»

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: