Created
October 24, 2013 03:49
-
-
Save masaru-b-cl/7131034 to your computer and use it in GitHub Desktop.
[1,2,3] から{0 => 1, 1 => 2, 3 => 2} を作りたい in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Collections.Generic; | |
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| namespace UnitTestProject1 | |
| { | |
| [TestClass] | |
| public class UnitTest1 | |
| { | |
| [TestMethod] | |
| public void TestMethod1() | |
| { | |
| var result = new[] { 1, 2, 3 } | |
| .Select((x, i) => new[] { i, x }) | |
| .ToDictionary(x => x[0], x => x[1]); | |
| Assert.AreEqual(1, result[0]); | |
| Assert.AreEqual(2, result[1]); | |
| Assert.AreEqual(3, result[2]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment