C# Program to Demonstrate the IDumpable Interface

This C# Program Demonstrates IDumpable Interface.Here the Dumpable Interface is demonstrated with the use of Dump method.

Here is source code of the C# Program to Demonstrate IDumpable Interface. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

  1. /*
  2.  * C# Program to Demonstrate IDumpable Interface
  3.  */
  4. using System;
  5. interface IDumpable
  6. {
  7.     string Name { get; set; }
  8.     void Dump();
  9. }
  10.  
  11. class Fraction : IDumpable
  12. {
  13.     int z, n;
  14.     string name;
  15.  
  16.     public Fraction(int z, int n)
  17.     {
  18.         this.z = z; this.n = n;
  19.     }
  20.  
  21.     public string Name
  22.     {
  23.         get
  24.         {
  25.             return name;
  26.         }
  27.         set
  28.         {
  29.             name = value;
  30.         }
  31.     }
  32.  
  33.     public void Dump()
  34.     {
  35.         Console.WriteLine("Fraction : " + z + "/" + n);
  36.     }
  37. }
  38.  
  39. class Person : IDumpable
  40. {
  41.     string name;
  42.     public string address;
  43.     public int phone;
  44.  
  45.     public Person(string name, string address, int phone)
  46.     {
  47.         this.name = name; this.address = address; this.phone = phone;
  48.     }
  49.  
  50.     public string Name
  51.     {
  52.         get { return name; }
  53.         set { name = value; }
  54.     }
  55.  
  56.     public void Dump()
  57.     {
  58.         Console.WriteLine("Person Details : {0}, {1}, {2}", name, address, phone);
  59.     }
  60. }
  61.  
  62. class Test
  63. {
  64.  
  65.     static void Main(string[] arg)
  66.     {
  67.         IDumpable[] a = 
  68.         {
  69.             new Fraction(10,3),
  70.             new Fraction(9,4),
  71.             new Person("Tom", "INDIA", 99556677),
  72.             new Person("Jerry", "INDIA", 998979899),
  73.         };
  74.         a[0].Name = "f1";
  75.         a[1].Name = "f2";
  76.         foreach (IDumpable obj in a)
  77.         {
  78.             Console.Write(obj.Name + ": ");
  79.             obj.Dump();
  80.         }
  81.         Console.ReadLine();
  82.     }
  83.  
  84. }

Here is the output of the C# Program:

f1 : Fraction : 10/3
f2 : Fraction : 9/4
Tom : Person Details : Tom, INDIA, 99556677
Jerry : Person Details :Jerry, INDIA, 998979899

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

advertisement
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 20s–40s and exploring new directions in your career, I also offer mentoring. Learn more here.