// Access Modifier: Determines the visibility of the class (e.g., public, private)
// Class Keyword: Indicates the definition of a class
// Class Name: The name of the class (follows naming conventions)
// Class Body: Contains fields, properties, methods, and other members
public class MyClass
{
// Fields: Variables to store data
private int myField;
// Properties: Accessors for fields, allowing controlled access
public int MyProperty
{
get { return myField; }
set { myField = value; }
}
// Constructor: Special method called when an object is created
public MyClass()
{
// Initialization logic here
}
// Methods: Functions that perform operations on the class
public void MyMethod()
{
// Method logic here
}
// Other Members: Events, indexers, nested classes, etc.
// Destructor: Special method called when an object is destroyed (rarely used)
~MyClass()
{
// Cleanup logic here
}
}
- 필드( Fields ) : 클래스 내에서 데이터를 저장하는 변수입니다. 가시성과 접근성을 제어하기 위해 다양한 액세스 수정자(공개, 비공개, 보호 등)를 가질 수 있습니다.
- 프로퍼티(Properties) : 클래스의 내부 상태를 노출하여 액세스를 제어하는 데 사용됩니다. 이는 getter와 선택적으로 setter 메소드로 구성됩니다.
- 메서드(Methods) : 클래스의 동작을 정의하는 함수입니다. 다양한 작업을 수행하고 클래스의 데이터를 조작할 수 있습니다.
- 생성자(Constructors): 객체가 생성될 때 호출되는 특수 메서드입니다. 객체의 상태를 초기화합니다. 서로 다른 매개변수 목록을 가진 여러 생성자가 있을 수 있습니다.
- 소멸자(Destructor (Finalizer)): C#에서는 거의 사용되지 않는 특수 메서드로, 가비지 수집기에 의해 개체가 소멸되려고 할 때 호출됩니다. 물결표(~) 뒤에 클래스 이름이 표시됩니다.
- 기타 멤버: 클래스에는 요구 사항에 따라 이벤트, 인덱서, 중첩 클래스 등과 같은 다른 요소가 포함될 수 있습니다.
'개발 > C#' 카테고리의 다른 글
[Console] 콘솔 키 입력 방법 (1) | 2024.01.05 |
---|---|
Property (0) | 2024.01.05 |
System.Text.Json (0) | 2024.01.05 |
[Console] Background/Foreground Color (0) | 2024.01.04 |
[Console] 창 크기 조절 (0) | 2024.01.03 |