[C#] 15화 this 레퍼런스
by #독개#class Player
{
int Hp;
int Att;
private static int Mp; //정적 맴버변수만을 정적 맴버함수에서 사용할 수 있다.
//Static 맴버함수는 객체를 만들지 않고도 사용할수 있으므로 객체화 되지 않는다. 즉 this가 없다.
//그래서 정적맴버함수는 맴버변수를 사용할수없다. this가없으므로
public static void Pvp(Player _Left, Player _Right)
{
_Left.Hp -= _Right.Att;
Mp = 44;
}
//맴버함수에서 맴버변수를 쓴다면 눈에보이지는 않지만 this.이 생략된 것이다.
public void Heal(/*Player this,*/ int _Heal) //맴버함수의 호출은 실제로 나자신을 받는 매개변수를 생략시켜있다
{
this.Hp += _Heal;
}
}
namespace _15화_This_레퍼런스
{
internal class Program
{
static void Main()
{
Player player1 = new Player();
Player player2 = new Player();
Player player3 = new Player();
player1.Heal(/*player1,*/ 50); //이렇게 매번 자기자신의 객체이름 넣어줄수 없으니까 자동포함생략
}
}
}
블로그의 정보
독한 개발자
#독개#