본문 바로가기
반응형

c#5

[C#] 배열 C#은 C와 배열 선언 방법이 다르다. C#에서 배열 선언 방법이 항상 헷깔린다. C#에서 배열 선언은 다음과 같다. int[] array = new int[5];int[] array = new int[] { 1, 3, 5, 7, 9 }; C에서 int array[5]와 같이 선언하는 것에 비해 확실히 복잡하다. =이 들어가고 왼쪽에 [], 오른쪽에 new가 추가되어 총 3개가 더 추가된다. 쉽게 기억하는 방법은 C#에서는 배열을 객체로 다루기 때문에 int[]라는 객체로 array를 instance로 선언하고 new int[5]로 새로운 int[] 객체를 생성한다고 보면 된다. [5]는 객체에 전달되는 arguement로 보면 된다. 2017. 4. 9.
[C#] 윈도우의 위치와 크기 저장하기 1. 먼저 아래와 같이 Location과 Size를 추가한다. 값에는 초기값을 넣는다. 2. Form load와 closing에 다음과 같은 코드를 넣는다. // Form loadprivate void Form1_Load(object sender, EventArgs e){this.Size = Properties.Settings.Default.Size;this.Location = Properties.Settings.Default.Location;} // Form closingprivate void Form1_FormClosing(object sender, FormClosingEventArgs e){Properties.Settings.Default.Size = this.Size;Properties.Setti.. 2016. 8. 10.
[C#] 파일/폴더의 이름 바꾸기 Move 명령은 파일/폴더를 이동시키는 함수이지만, Move 명령을 같은 폴더에서 이름을 달리하여 사용하면 이름이 바뀐다. 파일의 이름을 바꾸는 메소드는 다음 과 같다. System.IO.File.Move(Source, Destination); 폴더의 이름을 바꾸는 메소드는 다음 과 같다. System.IO.Directory.Move(Source, Destination); 2016. 5. 7.
[C#] 폴더의 파일 찾기 다음 명령어를 사용하면 폴더내의 전체 경로를 포함한 파일 이름이 string에 저장된다. string[] filepath = Directory.GetFiles(@"D:\_Temp\", "*.*", SearchOption.TopDirectoryOnly); 하위 폴더의 파일까지 찾을 때는 다음 명령어를 사용한다. string[] filepath = Directory.GetFiles(@"D:\_Temp\", "*.*", SearchOption.AllDirectories); 폴더내의 하위 폴더의 전체 경로는 다음 명령어를 사용하여 구한다. string[] dirs = Directory.GetDirectories(@"D:\_Temp\"); 전체 경로를 포함한 문자열에서 파일 이름만 얻기 위해서는 다음 명령어를 사.. 2016. 4. 17.
[C#] ListView에 Item 추가하는 방법 C#에서 ListView에 Item 추가하는 방법 listView1.View = View.Details;listView1.GridLines = true;listView1.FullRowSelect = true;// Add columnlistView1.Columns.Add("No", 30);listView1.Columns.Add("Name", 500); // Add itemsstring[] arr = new string[4];ListViewItem itm; // Add itemarr[0] = "1";arr[1] = "Name 1";itm = new ListViewItem(arr);listView1.Items.Add(itm); arr[0] = "2";arr[1] = "Name 2";itm = new ListV.. 2016. 4. 17.
반응형