Object Initializer 사용법을 설명하는 샘플코드이다. using System; namespace Sample { class Program { static void Main(string[] args) { Line L1 = new Line(); Point myP1 = new Point(); myP1.X = 1; myP1.Y = 2; Point myP2 = new Point(); myP2.X = 3; myP2.Y = 4; L1.P1 = myP1; L1.P2 = myP2; Console.WriteLine(L1.ToString()); Line L2 = new Line(); Point itsP1 = new Point { X = 5, Y = 6 }; // Object Initializers Point i..
Object Initializer를 이용하는 간단한 샘플코드이다. 아래에서 P1과 P2의 property에 값을 대입하는 방식을 살펴보라. using System; namespace Sample { class Program { static void Main(string[] args) { Point P1 = new Point(); P1.X = 2; P1.Y = 3; Console.WriteLine(P1.ToString()); // Object Initializers Point P2 = new Point { X = 7, Y = 8 }; Console.WriteLine(P2.ToString()); } } public class Point { int x; public int X { get { return x; ..
간단한 Lambda Expression 샘플 코드이다. Lambda Expression에서 return 값을 살펴보자. using System; namespace LambdaSample { class Program { delegate int Action(int number); static void Main(string[] args) { Action action1 = number => number + 2; Action action2 = number => { return number + 2; }; int i = action1(3); int j = action2(3); Console.WriteLine(i); Console.WriteLine(j); } } }
Anonymous Method와 Lambda Expression을 비교해보자. Lambda Expression이 조금 더 단순해보인다. using System; namespace DelegateSample { class Program { static void Main(string[] args) { Human Tom = new Human(); // Anonymous Method Tom.ActionDelegate += delegate(string text) { Console.WriteLine("Anonymous:" + text); }; // Lambda Expression Tom.ActionDelegate += (string text) => Console.WriteLine("Lambda1:" + text);..
Extension Methods 사용법은 2가지이다. 기존의 static method 사용법과 동일하게 쓰는 방법도 가능하다. 아래 예제는 exception 발생없이 잘 실행된다. Extension methods are static methods. Extension methods can only be declared in static classes. using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "123"; int i = s.ToInt32(); int j = Extensions.ToInt32(s); Console.WriteLine(i); Console.Write..
const 대 readonly 비교 using System; namespace Test { class Program { static void Main(string[] args) { Some s1 = new Some(); Console.WriteLine(Some.constField); // const : 항상 static Console.WriteLine(s1.readonlyField1); Console.WriteLine(s1.readonlyField2); Some s2 = new Some(5); Console.WriteLine(s2.readonlyField2); } } class Some { // const readonly 공통 : 클래스 밖에서 값을 바꿀 수 없음 // const : 항상 static (..
SetForegroundWindow 메쏘드를 이용한 샘플 코드이다. 1초에 한번씩 노트패드에 "abc " 스트링을 입력을 하는 것이다. using System; using System.Diagnostics; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ControlHandle { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.timer1.Interval = 1000; this.timer1.Enabled = true..
Process 클래스를 이용해서 원하는 Window(Process)의 핸들값을 얻는 샘플 코드이다. using System; using System.Diagnostics; using System.Windows.Forms; namespace ControlHandle { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = String.Empty; Process[] processes = Process.GetProcessesByName("notepad"); foreach (Process ..
앞에서 보였던 GenericDictionaryXmlSerializer 클래스 2 사용 예제이다. using System; using System.Collections.Generic; using System.Xml; using GenericDictionaryXmlSerialization; namespace TestGenericDictionaryXmlSerialization { class Program { static void Main(string[] args) { Random myRandom = new Random(); Dictionary myDictionary = new Dictionary(); myDictionary["1st"] = myRandom.Next(10); myDictionary["2nd"] ..
GenericDictionaryXmlSerialization.GenericDictionaryXmlSerializer 클래스 코드입니다. 앞의 예제에서는 Deserialize mthod를 Deserialize(XmlReader reader, Dictionary dictionary) 형태로 해서 Dictionary를 파라미터로 받고 있습니다. 이런 형식은 XmlSerializer.Deserialize method와는 다른 형식이죠. 아래의 클래스는 XmlSerializer.Deserialize method와 비슷한 형식입니다. 즉 파라미터로는 XmlReader만 받고 있습니다. 그리고 Dictionary 을 반환하고 있습니다. using System; using System.Collections.Generi..
- Total
- Today
- Yesterday
- tagREADYSTATE
- Microsoft
- iText
- WinAutomation
- AdSense감추기
- registry
- Rollback Rx
- AxWebBrowser
- ScreenHunter
- Service pack
- java
- autohotkey
- Phalanger
- 스크린캡쳐
- READYSTATE_COMPLETE
- DotNetMagic
- 애드센스감추기
- iTextSharp
- 유틸리티
- download.com
- Automation
- 애드센스숨기기
- c#
- Sample Code
- jre
- windows
- Regular Expressions
- AdSense숨기기
- .net framework
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |