S_pot
C#_this키워드를 사용하는이유 본문
this키워드는 객체가 자기 자신을 지칭할 때 사용
클래스 내부에서 필드명과, 메서드의 매개 변수의 이름이 동일할 때
this 키워드로 모호성을 제거
this가 붙은 변수는 클래스의 자신의 필드이며 그 외는 매개 변수이다.
using System;
namespace This
{
class Employee
{
private string Name;
private string Position;
public void SetName(string Name)
{
this.Name = Name;
}
'C#' 카테고리의 다른 글
C#_Split: 입력값 띄어쓰기 (0) | 2021.06.27 |
---|---|
C#_try-catch-finally문 (1) | 2021.06.27 |
C#_delegate2:익명메서드, 람다식 (0) | 2021.06.14 |
C#_delegate2:익명메서드, 람다식 (0) | 2021.06.14 |
C#_MessageMap기법: 속성으로 문자와 delegate를 만들어 효율적으로 값을 호출 (0) | 2021.06.14 |