vimwiki/tech/interface.wiki

38 lines
1.4 KiB
Plaintext
Raw Normal View History

2022-02-22 20:30:01 +00:00
= Interface =
An interface is a paradigm where an abstract class defines some set of abstract
functions that a class inheriting it can define. This is a core concept in C#.
In C# an interface can be declared with the `interface` keyword in its
declaration. However, there are several built in interfaces that are very
useful.
== Built in C# interfaces ==
=== System.IComparable ===
Something that wants to be IComparable must impliment
`public int CompareTo(object obj)`. This must return,
* Less than zero if the current instance preceds the object specified in sort
order
* Zero if the current instance is in the same position in the sort order as the
given object
* Greater than zero if the current instance follows the object given
All numeric types already have this, as do String Char and DateTime
=== System.IDisposable ===
Something that is IDisposable can be freed, it is very useful when working with
unmanaged resources, like database connections or filestreams. To impliment
this, a class must impliment `public void Dispose()`. This Dispose function
will be called if the object is used in a `using()` block statement for
example.
=== System.IEnumerable ===
Something that is IEnumerable can be used with an enumerator object. This
allows some object to work with LINQ queries. IEnumerable also requires
`IEnumerator<T>` to be defined. `IEnumerator<T>` also needs
[[#System.IDisposable]] to be implimented.