के लिए तत्काल विंडो में अलग काम करती है object boxedInt = 0
, अपने कोड में परिभाषित दृश्य स्टूडियो के तत्काल विंडो में दोनों is object
और is int
वापसी false
। यह एक बग है, है ना?"है" ऑपरेटर एक बॉक्स्ड <code>int</code>, उदा लिए बॉक्स्ड मूल्यों
कोड:
int normalInt = 0;
Debug.WriteLine(normalInt.GetType().FullName); // System.Int32
Debug.WriteLine(normalInt is object); // true
Debug.WriteLine(normalInt is int); // true
Debug.WriteLine(normalInt is System.Int32); // true
object boxedInt = 0;
Debug.WriteLine(boxedInt.GetType().FullName); // System.Int32
Debug.WriteLine(boxedInt is object); // true
Debug.WriteLine(boxedInt is int); // true
Debug.WriteLine(boxedInt is System.Int32); // true
तत्काल विंडो:
normalInt.GetType().FullName
"System.Int32"
normalInt is object
true
normalInt is int
true
normalInt is System.Int32
true
boxedInt.GetType().FullName
"System.Int32"
boxedInt is object
false // WTF?
boxedInt is int
false // WTF?
boxedInt is System.Int32
false // WTF?
object boxedInt2 = 0;
Expression has been evaluated and has no value
boxedInt2.GetType().FullName
"System.Int32"
boxedInt2 is object
true
boxedInt2 is int
true
boxedInt2 is System.Int32
true
माइक्रोसॉफ्ट विजुअल स्टूडियो एंटरप्राइज 2017
संस्करण 15.3.3
VisualStudio.15.Release/15.3.3 + 26,730.12
माइक्रोसॉफ्ट .NET F ramework
संस्करण 4.7.02046
विजुअल C# 2017 00369-60000-00001-AA135
Watch
खिड़की के साथ स्क्रीनशॉट:
हां। उदा।, उपर्युक्त कोड के बाद ब्रेकपॉइंट सेट करते समय। –
मुझे लगता है कि आप do- करने के लिए 'boxedInt == typeof (वस्तु) है,' –
@SouvikGhosh 'boxedInt' एक' Type' वस्तु in't, ताकि सच कभी नहीं होगा। – Servy