Tom JERRY
This is a C# Program to demonstrate properties of the interface.
This C# Program Demonstrates Properties of the Interface.
Here the syntax for a property type on an interface declaration is different and the interface declarations do not include modifiers such as “public.”
Here is source code of the C# Program to Demonstrate Properties of the Interface. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Demonstrate Properties of the Interface */ using System; interface IValue { int Count { get; set; } string Name { get; set; } } class Image : IValue { public int Count { get; set; } string _name; public string Name { get { return this._name; } set { this._name = value; } } } class Article : IValue { public int Count { get; set; } string _name; public string Name { get { return this._name; } set { this._name = value.ToUpper(); } } } class Program { static void Main() { IValue value1 = new Image(); IValue value2 = new Article(); value1.Count++; value2.Count++; value1.Name = "Tom"; value2.Name = "Jerry"; Console.WriteLine(value1.Name); Console.WriteLine(value2.Name); Console.ReadLine(); } }
This C# program is used to demonstrate properties of the interface. The syntax for a property type on an interface declaration is different and the interface declarations do not include modifiers such as “public”. The interface IValue has a read-write property.Name, and a read-only property.count.
The class Image implements the IValue interface and uses these two properties. The program read the name of a new image and prints the name. The class Image and Article implement the IValue and have the Name property, the explicit interface member implementation will be necessary. That is, the following property declaration read-write instance property.
Tom JERRY