kutulu int
için farklı pencerelerde farklı çalışır. Kodunuzda belirtilen object boxedInt = 0
, hem is object
hem de is int
, Visual Studio'nun Anlık Penceresinde false
döndürür. Bu bir böcek değil mi?"is" operatörü, Kutulu değerler
Kodu:
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
Hemen Penceresi:
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
Microsoft Visual Studio Enterprise 2017
Sürüm 15.3.3
VisualStudio.15.Release/15.3.3 + 26.730,12
Microsoft .NET F
Versiyon ramework 4.7.02046
Visual C# 2017 00369-60000-00001-AA135
Ekran Watch
pencere ile: Araçlar-> Seçenek-> ayıklama altında
Evet. Örneğin, yukarıdaki koddan sonra bir kesme noktası ayarlarken. –
Sanırım yapmanız gereken - boxedInt == typeof (object); ' –
@SouvikGhosh' boxedInt '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'hiçbir zaman, bu asla doğru olmayacaktır. – Servy