티스토리 뷰
Object Initializer를 이용하는 간단한 샘플코드이다.
아래에서 P1과 P2의 property에 값을 대입하는 방식을 살펴보라.
아래에서 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; }
set { x = value; }
}
int y;
public int Y
{
get { return y; }
set { y = value; }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
}
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; }
set { x = value; }
}
int y;
public int Y
{
get { return y; }
set { y = value; }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
}
'Code > C#' 카테고리의 다른 글
iTextSharp 샘플코드 - Hello World (0) | 2008.04.08 |
---|---|
[C#] Object Initializer 사용법 샘플 코드 (0) | 2008.02.11 |
[C#] 간단한 Lambda Expression 샘플 코드 (0) | 2008.02.11 |
[C#] Lambda Expression vs Anonymous Method (0) | 2008.02.11 |
[C#] Extension Methods 사용법 (0) | 2008.02.11 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- ScreenHunter
- iTextSharp
- jre
- Sample Code
- tagREADYSTATE
- AdSense감추기
- Service pack
- READYSTATE_COMPLETE
- 유틸리티
- Regular Expressions
- WinAutomation
- windows
- autohotkey
- AxWebBrowser
- DotNetMagic
- 스크린캡쳐
- java
- Phalanger
- Microsoft
- 애드센스감추기
- download.com
- Rollback Rx
- c#
- AdSense숨기기
- 애드센스숨기기
- registry
- iText
- .net framework
- Automation
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함