내가있어이 같은 코드 :왜 "! ="를 long과 비교할 수 없습니까?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
. . .
if (null != request.UserAgent)
{
str = String.Format("userAgent == {0}", request.UserAgent.ToString());
MessageBox.Show(str);
}
. . . // many other similar ones, comparing null to string, etc. types
하지만이 하나 '! ='
if (null != request.ContentLength)
{
str = String.Format("contentLength == {0}", request.ContentLength.ToString());
MessageBox.Show(str);
}
...이, "운영자의 컴파일 타임 오류에 적용 할 수 없습니다 실패 유형의 피연산자 ''와 '에
가 나는 ToString을 추가 할 수 있습니다 "'롱 (받을)는 컴파일 :
if (null != request.ContentLength.ToString())
. . .
...하지만 이상하게 보입니다. HttpWebRequest의 ContentLength (long)가 null과 비교할 수없는 이유는 무엇입니까?
긴 null이 될 수 없다. null 값을 얻으려면 long/Nullable을 가져야합니다. –
왜? 그런 식으로 다른 데이터 유형과 구별되는 점은 무엇입니까? –
int, long, double, float 등은 값 유형이므로 null 가능 유형이 아니므로 null 일 수 있습니다. –