S_pot
210517 C#_class, 객체생성 본문
using System;
namespace _210517_007
{
class Human
{
public double tall; // 변수생성
public void eat() // 메서드생성
{
Console.WriteLine("냠냠냠...");
}
}
class Program
{
static void Main(string[] args)
{
int iNum; // 기본형: int
Human HumanObject; // 기본형: 객체참조변수, 이것은 객체가 아니라 객체를 참조하는 변수, 위치만 가지고 있기 때문에 크기는 고정
iNum = 100;
HumanObject = new Human(); // HumaObject는 객체의 위치이고 new Human()은 객체를 생성한 것이다.(인스턴스 생성)
HumanObject.tall = 1000;
HumanObject.eat();
Console.WriteLine("키 : " + HumanObject.tall);
}
}
}
출력값
'C#' 카테고리의 다른 글
210518 C#_namespace (0) | 2021.05.18 |
---|---|
210518 C#_소수 구하기 (0) | 2021.05.18 |
210517 C#_ref(래퍼런스) (0) | 2021.05.17 |
210517 C#_Swap(스왑), 출력값 위치 바꾸기 (0) | 2021.05.17 |
210517 C#_메서드를 이용한 5칙연산 (0) | 2021.05.17 |