mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
C#: interfaces
This commit is contained in:
parent
cae70d430e
commit
a225349acb
@ -557,6 +557,36 @@ namespace Learning
|
|||||||
return reuslt;
|
return reuslt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interfaces only contain signatures of the members, without the implementation.
|
||||||
|
interface IJumpable
|
||||||
|
{
|
||||||
|
void Jump(int meters); // all interface members are implicitly public
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IBreakable
|
||||||
|
{
|
||||||
|
bool Broken { get; } // interfaces can contain properties as well as methods, fields & events
|
||||||
|
}
|
||||||
|
|
||||||
|
// Class can inherit only one other class, but can implement any amount of interfaces
|
||||||
|
class MountainBike : Bicycle, IJumpable, IBreakable
|
||||||
|
{
|
||||||
|
int damage = 0;
|
||||||
|
|
||||||
|
public void Jump(int meters)
|
||||||
|
{
|
||||||
|
damage += meters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Broken
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return damage > 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} // End Namespace
|
} // End Namespace
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -567,7 +597,7 @@ namespace Learning
|
|||||||
* Attributes
|
* Attributes
|
||||||
* Generics (T), Delegates, Func, Actions, lambda expressions
|
* Generics (T), Delegates, Func, Actions, lambda expressions
|
||||||
* Static properties
|
* Static properties
|
||||||
* Exceptions, Interfaces, Abstraction
|
* Exceptions, Abstraction
|
||||||
* LINQ
|
* LINQ
|
||||||
* ASP.NET (Web Forms/MVC/WebMatrix)
|
* ASP.NET (Web Forms/MVC/WebMatrix)
|
||||||
* Winforms
|
* Winforms
|
||||||
|
Loading…
Reference in New Issue
Block a user