Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created October 24, 2013 03:49
Show Gist options
  • Select an option

  • Save masaru-b-cl/7131034 to your computer and use it in GitHub Desktop.

Select an option

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#
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