The source code to demonstrate the properties in the interface is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to demonstrate the properties in the interface.
using System;
interface Inf
{
int ID { get; set; }
string Name { get; set; }
}
class Student : Inf
{
string _name;
public int ID
{
get;
set;
}
public string Name
{
get { return this._name; }
set { this._name = value.ToUpper(); }
}
}
class Program
{
static void Main()
{
Inf inf = new Student();
inf.ID = 101;
inf.Name = "Rohit Sharma";
Console.WriteLine(inf.ID);
Console.WriteLine(inf.Name);
}
}
Output:
101
ROHIT SHARMA
Press any key to continue . . .
Explanation:
In the above program, we created an interface Inf that contains properties ID and Name then we implemented interface properties in the Student class.
Now look to the Program class, the Program class contains the Main() method, The Main() method is the entry point for the program. Here we created the object of Student class and initialized the inf reference.
Program:
The source code to demonstrate the properties in the interface is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created an interface Inf that contains properties ID and Name then we implemented interface properties in the Student class.
Now look to the Program class, the Program class contains the Main() method, The Main() method is the entry point for the program. Here we created the object of Student class and initialized the inf reference.
Here, we set the properties ID and Name.
In the above code, we get values using Get property and print them on the console screen.