using System;
namespace Field
{
public class Car
{
//변수Variable Type
public string name; //소문자로
//상수Constant Type : static -> 정적접근
public const int m_birth = 2010; //멤버변수의 의미
//읽기전용필드 Read Only
public static readonly string color = "Red"; //_언어바스코어->속성매치
}
public class Human
{
//이름을 저장할 공간 ? Field
private string _Name;
//이름을 외부에서 사용 : 속성(Property)
public string Name
{
get {
return _Name;
}
set {
_Name = value;
}
}
}
}
-----------------------------------------------------------
using System;
using Field; //네임스페이스 참조
public class 필드
{
public static void Main()
{
//Field.Car car = new Field.Car();
Car car = new Car();//Car클래스의 인스턴스 생성 의미
car.name = "에쿠스"; //이렇게 하면 안된다 (X)
// Car.color = "aa" Error
// Car.m_birth = 2009; Error
Human na = new Human(); //Human클래스의 인스턴스생성
na.Name = "홍길동"; //설정(set)
Console.WriteLine("이름 : {0}", na.Name); //사용(get)
}
}
'.Net Project > .Net 3.5 Sp1' 카테고리의 다른 글
51장 Desctructor(소멸자) (0) | 2009.08.11 |
---|---|
50장 Conistructor(생성자) (0) | 2009.08.11 |
48장 Class(클래스) (0) | 2009.08.11 |
47장 Locatioc(로케이션) (0) | 2009.08.10 |
46장 Document(문서) (0) | 2009.08.10 |