-
Notifications
You must be signed in to change notification settings - Fork 56
/
Program.cs
39 lines (33 loc) · 1.03 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace GenericTypes
{
class Program
{
static void Main()
{
var a = new NamedContainer<int>(42, "The answer");
var b = new NamedContainer<int>(99, "Number of red balloons");
var c = new NamedContainer<string>("Programming C#", "Book title");
// ...where a, and b come from #using_a_generic_class.
var namedInts = new List<NamedContainer<int>>() { a, b };
var namedNamedItem = new NamedContainer<NamedContainer<int>>(a, "Wrapped");
Show(a);
Show(b);
Show(c);
Show(namedInts);
Show(namedNamedItem);
}
public static void Show<T>(NamedContainer<T> c)
{
Console.WriteLine($"{c.Name}: {c.Item}");
}
public static void Show<T>(IEnumerable<NamedContainer<T>> cs)
{
foreach (NamedContainer<T> c in cs)
{
Show(c);
}
}
}
}