fork(1) download
  1. using System;
  2. using System.Threading;
  3. using System.Diagnostics;
  4. using System.Text;
  5. using System.Collections.Generic;
  6.  
  7. namespace Example
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<A> list = new List<A>();
  14. list.Add(new B("anton", 25));
  15. list.Add(new C("anton", 0, 545));
  16. list.Add(new D("anton", 25, 545, 545474));
  17. list.Add(new B("anhjyton", 25));
  18. list.Add(new C("anton", 25, 545));
  19. list.Add(new C("antofn", 25, 1111));
  20. foreach (A item in list)
  21. {
  22. B b = item as B;
  23. if (b != null)
  24. {
  25.  
  26. Console.WriteLine($"{b.Name} {b.age}");
  27. }
  28.  
  29. C c = item as C;
  30. if (c != null)
  31. {
  32. Console.WriteLine($"{c.Name} {c.age} {c.money}");
  33. }
  34.  
  35. D d = item as D;
  36. if (d != null)
  37. {
  38.  
  39. Console.WriteLine($"{d.Name} {d.age} {c.money} {d.SSN}");
  40. }
  41.  
  42. }
  43. }
  44. }
  45. abstract class A
  46. {
  47. public string Name { get; set; }
  48.  
  49. public A(string name)
  50. {
  51. Name = name;
  52. }
  53. }
  54. class B : A
  55. {
  56. public int age { get; set; }
  57. public B(string name, int age)
  58. : base(name)
  59. {
  60. this.age = age;
  61. }
  62. }
  63. class C : B
  64. {
  65. public int money { get; set; }
  66. public C(string name, int age, int money)
  67. : base(name, age)
  68. {
  69. this.money = money;
  70. }
  71. }
  72. sealed class D : C
  73. {
  74.  
  75. public D(string name, int age, int money, int SSN)
  76. : base(name, age, money)
  77. {
  78. this.SSN = SSN;
  79. }
  80.  
  81. public int SSN { get; set; }
  82. }
  83. }
Success #stdin #stdout 0.02s 16104KB
stdin
Standard input is empty
stdout
anton 25
anton 0
anton 0 545
anton 25
anton 25 545
anton 25 545 545474
anhjyton 25
anton 25
anton 25 545
antofn 25
antofn 25 1111