-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBase.cs
43 lines (36 loc) · 953 Bytes
/
Base.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace Generics;
public class Base
{
public static void UseBase(Base b)
{
}
public static void AllYourBase(IEnumerable<Base> bases)
{
}
public static void PassingIEnumerable()
{
IEnumerable<Derived> derivedItems = new[] { new Derived(), new Derived() };
AllYourBase(derivedItems);
}
public static void AddBase(ICollection<Base> bases)
{
bases.Add(new Base());
}
// Change to #if true to see compiler error
#if false
public void IllegalAddBase()
{
ICollection<Derived> derivedList = new List<Derived>();
AddBase(derivedList); // Will not compile
}
#endif
public static void UseBaseArray(Base[] bases)
{
bases[0] = new Base();
}
public static void PassDerivedElementTypeArray()
{
Derived[] derivedBases = [new Derived(), new Derived()];
UseBaseArray(derivedBases);
}
}