본문 바로가기

c# Dictionary3

[C#] Dictionary Value 內 List 중복 제거 내가 다루고 있는 Dictionary 형태는 Dictionary이며, 주로 구현하고자하는 기능은 새로운 Value 이 추가되었을 때, 기존에 갖고 있는 List을 제외하고 새로운 List만 가져오는 것이다. StackOverflow 구글링하다가 2가지 방법을 알았다. 1. List를 새로 생성하여 새로운 List를 만들어서 Dict 내 Key를 새로운 List로 바꾸기 // 할당된 경로 내 동일한 Dict Value List가 있는 경우 삭제 후 새로운 File Path Dict 생성 List dict_file_0_list = new List(); for (int i = 0; i < dict_file_0["Batch1"].Count; i++) { dict_file_0_list.Add(dict_file_0.. 2022. 5. 28.
[C#] JSON을 이용하여 Dictionary를 text file로 저장하기 1. Newtonsoft.Json NuGet을 설치한다. 2. 사용할 Class에 Newtonsoft.Json을 추가한다. using Newtonsoft.Json; 위 코드를 입력하면 JsonConvert를 사용할 수 있다. 3. Dictionary를 text file로 저장 File.WriteAllText("FileName.txt", JsonConvert.SerializeObject(dictionary)); 4. 저장한 text file을 다시 dictionary로 불러오기 var Loaded_Dictionary = JsonConvert.DeserializeObject(File.ReadAllText("FileName.txt")); Dictionary 형태는 저장하려는, 불러오려는 Dictionary 형.. 2022. 5. 27.
[C#] Dictionary Key Rename, Dictionary Key 이름 변경 Stack Overflow 검색하다보니, Dictionary Function 중 Key 이름 변경 Function은 없다고한다. 그래서 어떤 사람이 Method 만들어서 Dictionary Key 이름 변경하는 법을 보여줬다. private static void RenameKey(IDictionary dic, TKey fromKey, TKey toKey) { TValue value = dic[fromKey]; dic.Remove(fromKey); dic[toKey] = value; } 위 함수를 사용할 경우, RenameKey(dict_Batch_1, "Description", "Description: Date/Tag"); 로 입력하면 내가 원하는 Tag명을 새롭게 변경할 수 있다. 2022. 5. 24.