C#/수업내용
C# 21.03.29.수업내용
HappyFrog
2021. 3. 29. 14:33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
namespace Study801
{
class App
{
public App()
{
Console.WriteLine("App");
//스레드 변수 선언
Thread t;
ThreadStart ts = new ThreadStart(() =>
{
for(int i = 0; i < 10; i++)
{
Console.WriteLine("Hello");
Thread.Sleep(500);
}
});
//스레드 인스턴스화 (ThreadStart대리자 인스턴스화)
t = new Thread(ts);
//스레드 시작
t.Start();
Thread t2 = new Thread(new ThreadStart(this.Hi));
t2.Start();
}
private void Hi()
{
for(int i = 0; i < 10; i++)
{
Console.WriteLine("HI");
Thread.Sleep(500);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
namespace Study801
{
class App
{
static Thread thread1, thread2;
public App()
{
Console.WriteLine("App");
thread1 = new Thread(() =>
{
//Running : 스레드 시작 후 동작 상태
Console.WriteLine(thread1.ThreadState);
Thread.Sleep(1000);
thread1.Abort();
Thread.Sleep(1000);
thread1.Join();
});
thread1.Name = "Thread1";
//Unsterted : 스레드 생성 후 Start 되기 전 상태
Console.WriteLine(thread1.ThreadState);
thread1.Start();
thread2 = new Thread(() =>
{
while (true)
{
Thread.Sleep(100);
//WaitSleepJoin : 블록 상태, Join, Monitor Enter, Sleep일 때 되는상태
Console.WriteLine(thread1.ThreadState);
//Stopped : Abort메서드 호출시 되는 상태(중지된 스레드의 상태)
}
});
thread2.Start();
}
}
}
============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
namespace Study801
{
public class Coffee
{
}
public class Egg
{
}
public class Toast
{
public string bread;
public Toast(string bread)
{
this.bread = bread;
}
}
class App
{
public App()
{
//가변배열 선언
int[][] arr = new int[3][];
arr[0] = new int[2];
arr[1] = new int[6] { 1, 2, 3, 4, 5, 6 };
arr[2] = new int[3] { 7, 8, 9 };
int[] arr1 = arr[0];
Console.WriteLine(arr);
for(int i = 0; i < arr.Length; i++)
{
for(int j = 0; j < arr[i].Length; j++)
{
Console.WriteLine(arr[i][j] + " ");
}
Console.WriteLine();
}
}
}
}