Advertisement
Guest User

Dictionaries

a guest
May 23rd, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace dictionaries
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Dictionary<byte, int> dictionary = new Dictionary<byte, int>() { { 97, 2 }, { 98, 2 }, { 99, 2 }, { 100, 2 }, { 101, 2 }, { 13, 1 }, { 10, 1 }, };
  15.             string dictionaryString = string.Join("", dictionary.Select(kv => Convert.ToChar(kv.Key) + kv.Value.ToString() + "#").ToArray());
  16.             Console.WriteLine(dictionaryString);
  17.  
  18.             var dictionaryFromString = Regex.Matches(dictionaryString, @".\d+.").Cast<Match>().ToDictionary(x => Convert.ToByte(x.Value[0]), x => int.Parse(x.Value.Substring(1, x.Value.Length - 2)));
  19.  
  20.             foreach (var key in dictionaryFromString)
  21.             {
  22.                 Console.WriteLine(key.Key + " " + key.Value);
  23.             }
  24.  
  25.             Console.ReadLine();
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement