본문 바로가기

2/[ C# ]12

[C#] 특정 개수의 List 만들기 List YaxisDefault = new List(); for (int ii = 0; ii < XaxisTIME.Count; ii++) YaxisDefault.Add(0); 2023. 12. 8.
[C#] csv 파일에서 첫번째 열만 불러오기 ICollection XaxisTIME = new List(); string[] ValueTIME = File.ReadAllLines(file_path); foreach (string ValueTIMEList in ValueTIME) { XaxisTIME.Add(ValueTIMEList.Split(",")[0]); } 2023. 12. 8.
[C#] openFileDialog, 파일 불러오기 1. 도구상자에서 "openFileDialgo"를 Form 內 Drag 2. "File Browser" 버튼을 더블 클릭하여 Event 활성화 3. 아래 코드 입력 private void btnFileBrowser_Click(object sender, EventArgs e) { tboxFileAddress.Clear(); String file_path = null; // Current User's Desktop Address string localpath = Environment.GetFolderPath (Environment.SpecialFolder.Desktop); openFileDialog1.InitialDirectory = localpath; // Set openFileDialog's initia.. 2023. 12. 6.
[C#, Python] System.DllNotFoundException: 'DLL 'python37' C# GUI 작업하면서, ML.net을 사용하기 때문에 python37.dll 파일이 필요하다. https://www.dllme.com/ Download and Fix Missing .DLL Files - DLLme.com Download .DLL files for free and fix missing .DLL file errors. www.dllme.com 위 사이트를 통해서 python37.dll을 다운 받은 후, C:\Windows\System32 C:\Windows\SysWOW64 위 두 경로에 복사해서 넣어주면, 해결된다. 2022. 7. 12.
[C#] csv load using StreamReader using ExcelDataReader; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Threading.Tasks; namespace CSV_test { class Program { static void Main() { // 경로 내 csv를 저장할 빈 list 생성 List listpath = new List(); // openFileDialog로 처음에 경로 지정 ↓예시 string path = "C:\\Users\\KIERAN\\Desktop\\C# Test\\Data"; if (Directory.Exists(path)) { DirectoryInfo di = new Dir.. 2022. 6. 3.
[C#] csv load using DataTable using ExcelDataReader; using System; using System.Data; using System.IO; using System.Threading.Tasks; namespace CSV_test { class Program { static void Main() { // 경로 내 csv를 저장할 빈 list 생성 List listpath = new List(); // openFileDialog로 처음에 경로 지정 ↓예시 string path = "C:\\Users\\KIERAN\\Desktop\\C# Test\\Data"; if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); /// 지정한 경로 내 하위 .. 2022. 6. 3.
[C#] Pass Listbox items from Main Form to Sub Form 부모폼에 있는 Listbox의 items들을 자녀폼의 Listbox로 옮기는 방법이다. 자녀 품을 Show 해주는 Button이 있다. (혹은 다른 event) Main Form에 작성 private void button1_Click(object sender, EventArgs e) { SubForm f = new SubForm(listbox1.Items); f.show(); } Sub Form에 작성 public partial class SubForm : Form { public SubForm() { InitializeComponent(); } public SubForm(ListBox.ObjectCollection objectCollection) { InitializeComponent(); this.l.. 2022. 6. 1.
[C#] Graph Plot, Delete Series1 on Legend 위 그림 속 2번째 Graph의 Legend에 "Series 1"이라는 명명하지 않은 Series가 입력되어 있다. 이를 지우기 위해서는 Graph를 plot하기 전에 Series.Clear()를 아래 코드와 같이 해주면 된다. 그러면, 그림 속 1번째 Graph와 같이 Legend가 나온다. chartgraphname.Series.Clear(); chartgraphname에는 명명한 graph의 이름을 기입하면 된다. 2022. 5. 31.
[C#] Create Dictionary<string, List<string>> GUI 작업 중, combobox에서 선택된 text를 받아서 그래프를 plot하는 기능을 구현하던 중, Dictionary 형식이 필요했다. 아래와 같은 코드 형식으로 작성하면 위와 같은 Dictionary 형태를 만들 수 있다. Dictionary dict_cbox_list = new Dictionary() { {"A", new List { "Actual: A", "Prediction: A" } }, {"B", new List { "Actual: B", "Prediction: B" } }, {"C", new List { "Actual: C", "Prediction: C" } }, {"D", new List { "Actual: D", "Prediction: D" } }, {"E", new List { .. 2022. 5. 30.
[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.