-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCastArrayToIEnumerable.cs
More file actions
33 lines (26 loc) · 917 Bytes
/
Copy pathCastArrayToIEnumerable.cs
File metadata and controls
33 lines (26 loc) · 917 Bytes
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
using System;
using System.Collections;
using System.Collections.Generic;
public static class Program {
public static void AcceptIEnumerable (IEnumerable ie) {
object o = ie;
Console.WriteLine(o is IEnumerable ? "true" : "false");
foreach (var item in ie)
Console.WriteLine(item);
}
public static void AcceptIEnumerableT<T> (IEnumerable<T> ie) {
object o = ie;
Console.WriteLine(o is IEnumerable ? "true" : "false");
Console.WriteLine(o is IEnumerable<T> ? "true" : "false");
foreach (var item in ie)
Console.WriteLine(item);
}
public static void Main (string[] args) {
var a = new int[] { 0, 1, 2, 3, 4 };
object o = a;
AcceptIEnumerable(a);
AcceptIEnumerableT<int>(a);
AcceptIEnumerable((IEnumerable)o);
AcceptIEnumerableT<int>((IEnumerable<int>)o);
}
}