Users Online

· Guests Online: 33

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate Properties of the Interface

C# Program to Demonstrate Properties of the Interface

 

This is a C# Program to demonstrate properties of the interface.

Problem Description

This C# Program Demonstrates Properties of the Interface.

Problem Solution

Here the syntax for a property type on an interface declaration is different and the interface declarations do not include modifiers such as “public.”

Program/Source Code

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();
 
    }
}
Program Explanation

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.

Runtime Test Cases
 
Tom
JERRY

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.08 seconds
10,845,724 unique visits