You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Implementing and using interfaces<br />
using System;<br />
interface ICowboy<br />
{<br />
void Draw();<br />
string Name { get; }<br />
object this[int n] { get; }<br />
}<br />
Console.WriteLine(cb.Name);<br />
class Rancher : ICowboy<br />
{<br />
public void Draw() { Console.WriteLine("Bang!"); }<br />
public string Name { get { return("Tex"); } }<br />
public object this[int n] { get { return(...); } }<br />
}<br />
Using the interfaces<br />
class Wrangler : ICowboy<br />
{<br />
public void Draw() { Console.WriteLine("Bang!"); }<br />
public string Name { get { return("Woody"); } }<br />
public object this[int n] { get { return(...); } }<br />
}<br />
ICowboy cb = new Rancher();<br />
cb.Draw();<br />
Console.WriteLine(cb.Name);<br />
cb = new Wrangler();<br />
cb.Draw();<br />
Declaring and implementing the interfaces<br />
27