f1 : Fraction : 10/3 f2 : Fraction : 9/4 Tom : Person Details : Tom, INDIA, 99556677 Jerry : Person Details :Jerry, INDIA, 998979899
Users Online
· Guests Online: 41
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C# Program to Demonstrate the IDumpable Interface
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.
-
/*
-
* C# Program to Demonstrate IDumpable Interface
-
*/
-
using System;
-
interface IDumpable
-
{
-
string Name { get; set; }
-
void Dump();
-
}
-
-
class Fraction : IDumpable
-
{
-
int z, n;
-
string name;
-
-
public Fraction(int z, int n)
-
{
-
this.z = z; this.n = n;
-
}
-
-
public string Name
-
{
-
get
-
{
-
return name;
-
}
-
set
-
{
-
name = value;
-
}
-
}
-
-
public void Dump()
-
{
-
Console.WriteLine("Fraction : " + z + "/" + n);
-
}
-
}
-
-
class Person : IDumpable
-
{
-
string name;
-
public string address;
-
public int phone;
-
-
public Person(string name, string address, int phone)
-
{
-
this.name = name; this.address = address; this.phone = phone;
-
}
-
-
public string Name
-
{
-
get { return name; }
-
set { name = value; }
-
}
-
-
public void Dump()
-
{
-
Console.WriteLine("Person Details : {0}, {1}, {2}", name, address, phone);
-
}
-
}
-
-
class Test
-
{
-
-
static void Main(string[] arg)
-
{
-
IDumpable[] a =
-
{
-
new Fraction(10,3),
-
new Fraction(9,4),
-
new Person("Tom", "INDIA", 99556677),
-
new Person("Jerry", "INDIA", 998979899),
-
};
-
a[0].Name = "f1";
-
a[1].Name = "f2";
-
foreach (IDumpable obj in a)
-
{
-
Console.Write(obj.Name + ": ");
-
obj.Dump();
-
}
-
Console.ReadLine();
-
}
-
-
}
Here is the output of the C# Program:
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.