10 minpresentation

Generic Interfaces

Generic Interfaces

0 / 7 completed

Basic Generic Interface

csharp
1interface IContainer<T>
2{
3 T Value { get; set; }
4 bool HasValue { get; }
5}
6
7class Container<T> : IContainer<T>
8{
9 public T Value { get; set; }
10 public bool HasValue => Value != null;
11
12 public Container(T value)
13 {
14 Value = value;
15 }
16}
17
18// Usage
19IContainer<int> intContainer = new Container<int>(42);
20IContainer<string> strContainer = new Container<string>("Hello");
Step 1 of 7
← → NavigateSpace: Skip / NextEnter: Next