Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How do I copy the content of a dictionary to an new dictionary in C#?
- Dictionary<string, string> d = new Dictionary<string, string>();
- Dictionary<string, string> d2 = new Dictionary<string, string>(d);
- Dictionary<string, string> d = new Dictionary<string, string>();
- Dictionary<string, string> d2 = d;
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, string> first = new Dictionary<string, string>()
- {
- {"1", "One"},
- {"2", "Two"},
- {"3", "Three"},
- {"4", "Four"},
- {"5", "Five"},
- {"6", "Six"},
- {"7", "Seven"},
- {"8", "Eight"},
- {"9", "Nine"},
- {"0", "Zero"}
- };
- Dictionary<string, string> second = new Dictionary<string, string>();
- foreach (string key in first.Keys)
- {
- second.Add(key, first[key]);
- }
- first["1"] = "newone";
- Console.WriteLine(second["1"]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment