본문 바로가기

프로그래밍/C#.net30

은폐 ■악세스레벨(Accessibility Level) 악세스레벌 설명 public 어디서든지 악세스가능 protected class내부와 파생class내부에서만 악세스가능 internal 동일project내의 class에서만 악세스가능 protected internal 동일project내의 class내부와 파생class내부에서 악세스가능 private class내부에서만 악세스가능 예를 들어 class A { public int pub; protected int pro; private int pri; public void function1() { // class 내부 pub = 1; // OK pro = 2; // OK pri = 3; // OK } } class B : A { public void func.. 2009. 8. 24.
Constructor 1.콘스트럭터는 인스턴스를 초기화하기 위한 특별한 메소드이다. class SampleClass { SampleClass() { //인스턴스의 초기화용 코드를 쓴다. } } 2.다른 메소드와 틀려서, 반환값의 형은 쓰지않는다. 즉,콘스트럭터는 반환값을 돌려주지 못한다. class Person { public string name; // 이름 public int age; // 나이 // ↓이것이 Person클래스의 constructor public Person() { name = ""; age = 0; } } 3.콘스드럭터는 인수를 부여할수도 있다. class Person { public string name; // 이름 public int age; // 나이 // ↓이것이 Person클래스의 constru.. 2009. 8. 24.
클래스 ■클래스와 인스턴스 오브젝트를 만들때, 먼저 설계도가 필요하다. 내부가 어떤구조로 되어있는지, 외부에거 어떤 조작이 되는지를 결정하게 된다. 이런 오브젝트 설계도를 클래스(class)라고 한다. 이것에 대해, 설계도를 가지고 만들어진 오브젝트의 실체를 인스턴스(instance)라고 한다 ■클래스 정의 class 클래스명 { 클래스 실제 부품구현 } ■클래스 이용 클래스를 사용하기 위해서는 인스테스를 작성해야 된다. 1.인스턴스를 격납하는 변수를 정의한다. 클래스명 변수명; 2.new 키워드로 인스턴스를 작성해서, 준비한 변수를 격납한다. 변수 = new 클래스명(); 그리고, 변수뒤에 점(.)으로 나누어서 멤버명을 쓰면 멤버변수와 메소드를 사용할수 있다. 변수이름.멤버이름 ■클래스의 분할정의 ver.2... 2009. 8. 24.
작업표시줄에 App 숨기는 꽁수 public class TaskbarController { [DllImport("user32.dll")] private static extern int FindWindow(string className, string windowText); [DllImport("user32.dll")] private static extern int ShowWindow(int hwnd, int command); private const int SW_HIDE = 0; private const int SW_SHOW = 1; private static int _GetTrayHandler() { return FindWindow("Shell_TrayWnd", ""); } public static void ShowTaskbar() {.. 2009. 3. 24.
바탕화면을 부모로 가지기 public partial class Form1 : Form { [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] private static extern IntPtr GetWindow(IntPtr hWnd, int uCmd); [DllImport("User32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); private const int GW_CHILD = 5; public Form1() { InitializeC.. 2009. 3. 24.
FormBorder.None 에 간단하게 드래그이벤트 추가 코드 usingSystem; usingSystem.Windows.Forms; usingSystem.Runtime.InteropServices; namespaceDragFormSample { publicpartialclassDragFormSample:Form { [DllImport("user32.dll")] publicstaticexternintSendMessage(IntPtrhWnd,intmsg,intwParam,intlParam); [DllImport("user32.dll")] publicstaticexternboolReleaseCapture(); publicreadonlyintWM_NLBUTTONDOWN= 0xA1; publicreadonlyintHT_CAPTION= 0x2; publicDragFormSa.. 2009. 3. 24.
WinService구동시 installutil문제 내컴퓨터 - 환경변수 - Path에 추가하자C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM gpedit.msc 2009. 2. 17.
[C#] AutoResetEvent 와 ManualResetEvnet 예제 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;namespace WaitHandleTest1 { class ThreadPlayer { private string m_name; //이름 private Random m_random; //달리기속도를 다르게 하기 위한 Random //이벤트. 맨처음에 이벤트 발생이면 true 아님 false private ManualResetEvent m_event = new ManualResetEvent(false); // private AutoResetEvent m_event = new AutoResetEvent(false);.. 2009. 1. 15.
동기화 테스트 예제 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;namespace SyncTest1 { class Sync { int m_count = 0; public int Count { get { return m_count; } } public void Count100() { for (int i = 0; i < 100; i++) { //Monitor.Enter(this); //try //{ lock(this) { int temp = m_count; Thread.Sleep(1); temp++; //Interlocked.Increment(ref temp); m_count =.. 2009. 1. 15.