Skip to content

Instantly share code, notes, and snippets.

@goshki
Created December 30, 2015 07:17
Show Gist options
  • Save goshki/c7e7f47818e345f671b6 to your computer and use it in GitHub Desktop.
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.).
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