Advertisement
Shirai

Get Object Type

Mar 29th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace TypeOf
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             IA a = new A1();
  16.             IA b = new A2();
  17.             IA c = new A3();
  18.             var d = new A4();
  19.             var list = new ArrayList();
  20.             list.Add(a);
  21.             list.Add(b);
  22.             list.Add(c);
  23.             list.Add(d);
  24.             foreach (var item in list)
  25.             {
  26.                 Console.Write(item.GetType());
  27.                 if (item is IA)
  28.                 {
  29.                     Console.Write(" is IA");
  30.                 }
  31.                 if (item is BaseA)
  32.                 {
  33.                     Console.Write(" is BaseA");
  34.                 }
  35.                 Console.Write(" Based from" + item.GetType().BaseType);
  36.                 foreach (var ifType in item.GetType().GetInterfaces())
  37.                 {
  38.                     Console.Write(" Implemented " + ifType);
  39.                 }
  40.  
  41.                 Console.WriteLine();
  42.             }
  43.             Console.ReadKey();
  44.         }
  45.     }
  46.     public class A1: BaseA,IA { }
  47.     public class A2: IA, IB { }
  48.     public class A3: BaseA,IA { }
  49.     public class A4: BaseA { }
  50.  
  51.     interface IA
  52.     {
  53.        
  54.     }
  55.  
  56.     interface IB
  57.     {
  58.        
  59.     }
  60.     public abstract class BaseA
  61.     {
  62.        
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement