2017-09-07 45 views
9

के लिए तत्काल विंडो में अलग काम करती है 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 खिड़की के साथ स्क्रीनशॉट:

+0

हां। उदा।, उपर्युक्त कोड के बाद ब्रेकपॉइंट सेट करते समय। –

+0

मुझे लगता है कि आप do- करने के लिए 'boxedInt == typeof (वस्तु) है,' –

+3

@SouvikGhosh 'boxedInt' एक' Type' वस्तु in't, ताकि सच कभी नहीं होगा। – Servy

उत्तर

1

उपकरण> विकल्प> डिबगिंग के तहत , कृपया "विरासत सी # और वीबी अभिव्यक्ति मूल्यांकनकर्ताओं का उपयोग करें" विकल्प सक्षम करें, इसे दोबारा डीबग करें।

enter image description here

अद्यतन:

यहां मुद्दा यह सूचना दी गई है:

https://developercommunity.visualstudio.com/content/problem/31283/and-operation-of-boolean-is-wrong.html

+0

यह एक सहायक उत्तर है क्योंकि यह वास्तव में काम करता है। हालांकि, यह जवाब नहीं देता है कि आप गैर विरासत (यानी बेहतर होना चाहिए) मोड में मनाए गए व्यवहार को क्यों चाहते हैं और क्या यह एक बग हो सकता है। मैं इसे वोट देता हूं लेकिन इसे सही उत्तर के रूप में स्वीकार नहीं करता हूं। –

+0

@ मार्को एक्स्टीन, मैं इस मुद्दे की रिपोर्ट करूंगा और अन्य सदस्यों के साथ चर्चा करूंगा, अगर मुझे कोई नवीनतम जानकारी मिलती है, तो मैं इसे यहां साझा करूंगा। –

+0

@ मार्को एक्स्टीन, इसी तरह की समस्या यहां रिपोर्ट की गई है: https://developercommunity.visualstudio.com/content/problem/31283/and-operation-of-boolean-is-wrong.html, उत्पाद टीम के सदस्य इसका अनुसरण करेंगे , आप वहां अपनी टिप्पणी भी साझा कर सकते हैं। –

संबंधित मुद्दे