मुझे यह समझने में कठिनाई हो रही है। निम्न उदाहरण पर विचार करें:सी # - मुक्केबाजी/अनबॉक्सिंग/टाइपकास्टिंग इंक के साथ मुद्दे। मुझे समझ में नहीं आता
protected void Page_Load(object sender, EventArgs e)
{
// No surprise that this works
Int16 firstTest = Convert.ToInt16(0);
int firstTest2 = (int)firstTest;
// This also works
object secondTest = 0;
int secondTest2 = (int)secondTest;
// But this fails!
object thirdTest = Convert.ToInt16(0);
int thirdtest2 = (int)thirdTest; // It blows up on this line.
}
विशिष्ट त्रुटि है कि मैं रन टाइम पर मिल Specified cast is not valid.
अगर मैं दृश्य स्टूडियो में (int)thirdTest
QuickWatch है, मैं Cannot unbox 'thirdTest' as a 'int'
के एक मूल्य मिलता है।
यहां बिल्ली क्या चल रहा है?
Int16 वास्तव में एक छोटा सा है। तो मुझे लगता है कि आप 'Int16 firstTest = Convert.ToInt16 (0);' को प्रतिस्थापित कर सकते हैं; 'Int16 firstTest = 0s;' के साथ –