Category (302) 썸네일형 리스트형 간단한 DataGridView 사용 예제 DataGridView 사용에 대한 간단한 예제이다. DataGridView.ColumnCount 를 사용해서 열의 갯수를 정한다. DataGridView.Columns[].Name 으로 각 열의 이름을 정한다. DataGridView.Rows.Add() 를 이용해서 행을 추가한다. using System; using System.Windows.Forms; namespace DataGridViewSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.dataGridView1.ColumnCount .. C# & .NET , BCL에 대한 단상 C#과 .NET을 공부하다 보면 Base Class Library에 정말 별의별것들이 다 있다는 생각을 하게 된다. 프로그램을 만들기 위해서 특별히 다른 라이브러리를 구할 필요가 거의 없을 지경이다. 문제는 도대체 어떤 것들이 있는지를 파악하기 어렵다는 것이다. 너무 많기 때문이다. C# 문법 자체에 대한 공부도 중요하지만, BCL 안에 어떤 것들이 있는지 아는 것도 중요할 것이다. BCL에 대해서 정리해 놓은 책을 하나 구해봐야겠다. 찜해 놓은 것이 하나 있긴 하다. Programming Microsoft Visual C# 2005: The Base Class Library (Pro-Developer) by Francesco Balena (Paperback - May 10, 2006) Publisher.. 단위 : Power Prefixes 단위는 헷갈리기 쉬운데, 아래 표에 정리되어 있다. 참고하기 바란다. DateTime & TimeSpan : 두 시간 사이의 간격 계산하기 두 시간 사이의 간격을 계산하기 위해서 DateTime 과 TimeSpan 을 사용할 수 있다. DateTime 은 측정하려는 두 시간을 구할 때 사용한다. TimeSpan 은 두 시간 사이의 간격을 계산할 때 사용한다. 아래 예제를 보자. using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { int result; int signature; TimeSpan oneSecond = TimeSpan.FromSeconds(1); Console.WriteLine(oneSecond); for (int i = 0; i < 10; i++) { DateTime old = Dat.. Thread.Sleep() & TimeSpan.FromSeconds() Thread.Sleep() 을 사용하면 일정 시간 동안 Thread를 멈출 수 있다. TimeSpan.FromSeconds() 을 사용하면 편하게 milli second 계산을 할 수 있다. 아래 예제를 살펴보자. using System; using System.Threading; namespace ThreadTest { class Program { static object locker = new object(); static void Main(string[] args) { new Thread(Go).Start(); for (int i = 0; i < 20; i++) { Console.Write("."); Thread.Sleep(TimeSpan.FromSeconds(1)); } } static void .. Thread 에서 locker의 사용 thread의 실행을 컨트롤하기 위해서 locker를 사용할 수 있다. locker는 오로지 lock을 하는 용도로만 쓰인다. 아래 예제를 살펴보자. using System; using System.Threading; namespace ThreadTest { class Program { static object locker = new object(); static void Main(string[] args) { new Thread(Go).Start(); lock (locker) { for (int i = 0; i < 500; i++) { Console.Write("."); } } } static void Go() { lock (locker) { for (int i = 0; i < 500; i++) { C.. static field를 사용한 Thread static field는 모든 Thread에서 공동으로 사용된다. 아래 예제를 살펴보자. using System; using System.Threading; namespace ThreadTest { class Program { // Static fields are shared between all threads static int count; static void Main(string[] args) { new Thread(Go).Start(); Go(); } static void Go() { for (int i = 0; i < 5; i++) { count++; Console.WriteLine(count); } } } } 위의 예제에서 count는 static field이다. 두개의 thread가 coun.. Thread에서 공동의 인스턴스 사용 예제 아래는 두개의 Thread가 공동의 instance를 사용한 예제이다. Foo 클래스 인스턴스인 foo를 공동으로 사용한 두개의 thread가 실행되었다. using System; using System.Threading; namespace ThreadTest { class Program { static void Main(string[] args) { Foo foo = new Foo(); new Thread(foo.Go).Start(); foo.Go(); } } class Foo { private int count = 0; public void Go() { for (int i = 0; i < 5; i++) { count++; Console.WriteLine(count); } } } } 실행 결과 화면은 .. 이전 1 ··· 25 26 27 28 29 30 31 ··· 38 다음