Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DefineAnInterfaceIPerson;
- using System;
- namespace PersonInfo
- {
- public class StartUp
- {
- static void Main(string[] args)
- {
- string name = Console.ReadLine();
- int age = int.Parse(Console.ReadLine());
- IPerson person = new Citizen(name, age); // IPerson don't have method "SayHi()"
- Console.WriteLine(person.Name);
- Console.WriteLine(person.Age);
- Type type = person.GetType(); // how to change from one type to another
- Citizen citizen = (Citizen)Convert.ChangeType(person, type);
- citizen.SayHi();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement