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.

advertisement

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

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

📌 Limited Seats! Register Now - Free AI-ML Certification (December 2025)
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.