Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace dictionaries
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<byte, int> dictionary = new Dictionary<byte, int>() { { 97, 2 }, { 98, 2 }, { 99, 2 }, { 100, 2 }, { 101, 2 }, { 13, 1 }, { 10, 1 }, };
- string dictionaryString = string.Join("", dictionary.Select(kv => Convert.ToChar(kv.Key) + kv.Value.ToString() + "#").ToArray());
- Console.WriteLine(dictionaryString);
- 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)));
- foreach (var key in dictionaryFromString)
- {
- Console.WriteLine(key.Key + " " + key.Value);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement