Interface Properties
In this chapter you will learn:
Adding properties to an interface
Here is the general form of a property specification:
// interface property
type name {
get;
set;
}
The following code create an interface with an empty property getter setting. The implementation provides logic to the getter.
using System;/*from j ava2s. c om*/
interface IVolumeControl
{
int Current
{
get;
}
}
interface ISpeedControl
{
int Current
{
get;
}
}
public class Radio : IVolumeControl, ISpeedControl
{
int IVolumeControl.Current
{
get
{
return 1;
}
}
int ISpeedControl.Current
{
get
{
return 2;
}
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
ISpeedControl radioDial = (ISpeedControl) new Radio();
Console.WriteLine( "Current Speed = {0}", radioDial.Current );
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class