type:of 와 GetType 의 차이
1519 단어 typeof
You can only use
typeof()
when you know that type at compile time, and you're trying to obtain the corresponding Type
object. (Although the type could be a generic type parameter, e.g. typeof(T)
within a class with a type parameter T
.) There don't need to be any instances of that type available to use typeof
. The operand for typeof
is always the name of a type or type parameter. It can't be a variable or anything like that. Now compare that with
object.GetType()
. That will get the actual type of the object it's called on. This means: GetType
on) One odd point:
GetType
will give unexpected answers on nullable value types due to the way that boxing works. A call to GetType
will always involve boxing any value type, including a nullable value type, and the boxed value of a nullable value type is either a null reference or a reference to an instance of a non-nullable value type.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
TIL_원시타입 객체 타입일단 여기서 중요한 개념은 변수를 선언하고 값을 할당하면 원시값에 해당하는 값들은 고정된 크기를갖고 스택메모리에 저장이되고 그 메모리주소를 변수가 갖게된다. 그리고 해당 변수에 다른값을 재할당할때 일어나는 동작은 다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.