linux-packaging-mono/mcs/tests/gtest-var-04.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

28 lines
617 B
C#

// 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;
}
}