C#
C#_this키워드를 사용하는이유
S_pot
2021. 6. 27. 14:04
this키워드는 객체가 자기 자신을 지칭할 때 사용
클래스 내부에서 필드명과, 메서드의 매개 변수의 이름이 동일할 때
this 키워드로 모호성을 제거
this가 붙은 변수는 클래스의 자신의 필드이며 그 외는 매개 변수이다.
using System;
namespace This
{
class Employee
{
private string Name;
private string Position;
public void SetName(string Name)
{
this.Name = Name;
}