Unity .NET 4.0 framework nameof연산자

 

nameof 연산자

nameof 연산자는 변수, 형식 또는 멤버의 문자열 이름을 가져옵니다. nameof가 유용하게 사용되는 몇 가지 경우는 오류 로깅 및 열거형의 문자열 이름 가져오기 등이 있습니다.

C#
// Get the string name of an enum:
enum Difficulty {Easy, Medium, Hard};
private void Start()
{
    Debug.Log(nameof(Difficulty.Easy));
    RecordHighScore("John");
    // Output:
    // Easy
    // playerName
}
// Validate parameter:
private void RecordHighScore(string playerName)
{
    Debug.Log(nameof(playerName));
    if (playerName == null) throw new ArgumentNullException(nameof(playerName));
}

댓글

이 블로그의 인기 게시물

About AActor!!! "UObject" has no member "BeginPlay"

UNREAL Android build information

C++ 생성자 위임 (delegating constructor)