Created
December 30, 2015 07:17
-
-
Save goshki/c7e7f47818e345f671b6 to your computer and use it in GitHub Desktop.
Convert a given list to a dictionary with subsequent letters as keys (A, B, C, etc.).
This file contains 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.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class ListToDictionary { | |
// Dictionary with subsequent letters as keys (A, B, C, etc.). Count should be less than or equal 24 | |
// to get reasonable results. | |
public Dictionary<string, string> ToDictionary(List<string> list) { | |
Dictionary<string, string> dictionary = new Dictionary<string, string>(list.Count); | |
for (int i = 0; i < list.Count; i++) { | |
// index used to calculate letter's position in ASCII table (A = 65, B = 66, C = 67, etc.) | |
dictionary.Add(Char.ConvertFromUtf32(i + 65), list[i]); | |
} | |
return dictionary; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment