이것은 앞의 예제를 약간 변형한 것이다. 2개의 Thread가 하나의 공통된 변수를 다루고 있다. 2개의 Thread가 하나의 int 변수에 발생한 난수를 더하고 있다. using System; using System.Threading; namespace SampleThread { class Program { static void Main(string[] args) { myRandom = new Random(); s = 0; Thread t1 = new Thread(new ThreadStart(method1)); t1.Start(); Thread t2 = new Thread(new ThreadStart(method2)); t2.Start(); } private static void method1() { ..
아래는 간단한 Thread 샘플 코드이다. 난수를 발생시키는 2개의 Thread가 있고, 발생한 난수만큼 Sleep 한다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace SampleThread { class Program { static void Main(string[] args) { myRandom = new Random(); Thread t1 = new Thread(new ThreadStart(method1)); t1.Start(); Thread t2 = new Thread(new ThreadStart(method2)); t2.Star..
아래는 Extension Methods 예제이다. LINE A는 Extension Methods를 사용했고, LINE B는 Static Method를 사용했다. 둘의 선언 방법과 사용 방법을 비교해보자. Extension methods are static methods. Extension methods can only be declared in static classes. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "9"; int ..
난수를 발생할 때, 중복되지 않는 것들로만 해야할 때가 있다. 이와 같은 경우에 사용할 수 있는 예제를 하나 만들어 보았다. List Generic Collection을 사용해서 만들었다. using System; using System.Collections.Generic; namespace RandomNumber { class Program { static void Main(string[] args) { Random myRandom = new Random(); List myList = new List(); int r; for (int i = 0; i < 3; i++) { do { r = myRandom.Next(5); } while (myList.Contains(r)); myList.Add(r); } ..
Jagged Array는 Multidimensional Array와는 다르므로 주의를 요합니다. 아래는 Jagged Array 선언 방법을 보여주는 샘플 코드입니다. Multidimensional Array와 헷갈리지 않도록 앞에 있는 Multidimensional Array 선언 방법과 비교해가며 보시기 바랍니다. namespace ArraySample { class Program { static void Main(string[] args) { // Jagged Array int[][] zArray; zArray = new int[3][]; zArray[0] = new int[] { 1, 2, 3 }; zArray[1] = new int[] { 1, 2 }; zArray[2] = new int[] { ..
아래는 3차원 Array 선언 방법을 보여주는 샘플 코드입니다. 조금 헷갈릴 수 있는데, 잘 살펴보시기 바랍니다. namespace ArraySample { class Program { static void Main(string[] args) { // An example of a three-dimensional array: int[, ,] array3D = new int[2, 3, 2] { { { 1, 2 }, { 1, 2 }, { 1, 2 } }, { { 1, 2 }, { 1, 2 }, { 1, 2 } } }; } } }
Array 선언 방법과 마찬가지로 Multidimensional Array 선언 방법도 몇가지가 있습니다. 아래는 Multidimensional Array 선언 방법을 보여주는 샘플 코드입니다. namespace ArraySample { class Program { static void Main(string[] args) { // Multidimensional Array int[,] array1; array1 = new int[2, 3]; int[,] array2 = new int[2, 3]; int[,] array3 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; int[,] array4 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }; in..
C#에서 array를 선언하는 방법은 몇가지가 있습니다. 아래는 int array를 선언하는 방법을 보여주는 샘플 코드입니다. namespace ArraySample { class Program { static void Main(string[] args) { // Array int[] aArray; aArray = new int[10]; int[] bArray = new int[5]; int[] cArray = new int[3] { 1, 2, 3 }; int[] dArray = new int[] { 1, 2, 3, 4, 5 }; int[] eArray = { 1, 2, 3, 4, 5 }; } } }
아래는 Random 예제이다. i 값이 20부터 1까지 하나씩 줄어든다. 이때, i 값 보다 작은 임의의 정수를 출력하는 예제이다. using System; namespace RandomSample { class Program { static void Main(string[] args) { Random myRandom = new Random(); for (int i = 20; i > 0; i--) { Console.WriteLine(myRandom.Next(i)); } } } }
아래는 Event에 Anonymous method를 추가하는 간단한 예제 코드이다. using System; namespace EventSample { public delegate void Conduct(); class Program { public static event Conduct myEvent; static void Main(string[] args) { myEvent += delegate() { Console.WriteLine("Hi"); }; myEvent += delegate() { Console.WriteLine("Ho"); }; myEvent(); } } }
- Total
- Today
- Yesterday
- Microsoft
- Rollback Rx
- autohotkey
- 애드센스감추기
- ScreenHunter
- DotNetMagic
- 스크린캡쳐
- c#
- iTextSharp
- WinAutomation
- iText
- jre
- AdSense숨기기
- 애드센스숨기기
- Phalanger
- java
- Sample Code
- .net framework
- windows
- AdSense감추기
- 유틸리티
- Regular Expressions
- tagREADYSTATE
- READYSTATE_COMPLETE
- Automation
- download.com
- Service pack
- registry
- AxWebBrowser
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |