blob: 04be4cff2cd4710dbfa1baea3e62125c0648f004 (
plain)
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
|
// Tests variable type inference with the var keyword when using the foreach statement with generic collections
using System;
using System.Collections.Generic;
public class Test
{
public static int Main ()
{
string[] strings = new string[] { "Foo", "Bar", "Baz" };
foreach (var v in strings)
if (v.GetType () != typeof (string))
return 1;
Dictionary<int, string> dict = new Dictionary<int, string> ();
dict.Add (0, "boo");
dict.Add (1, "far");
dict.Add (2, "faz");
foreach (var v in dict)
if (v.GetType () != typeof (KeyValuePair<int, string>))
return 2;
return 0;
}
}
|