本文介绍了谁能解释我为什么我们在拆箱过程中在大括号内写int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
拳击:
int a = 4;
对象Obj = a;
拆箱
int j =(int)obj;
谁能解释我为什么在大括号中编写int以及为什么我们不能编写convert.Toint32而不是编写(int)
感谢Advance
Hi All,
Boxing:
int a=4;
object Obj=a;
Unboxing
int j=(int)obj;
Can anybody explain me why do we write int in the braces and why can not we write convert.Toint32 instead of writing (int)
Thanx in Advance
推荐答案
object o = 123; int i = (int) o; int j = Convert.ToInt32(o);
这两个语句在功能上是等效的,但是前者更易于阅读,尤其是当表达式更复杂时而不是简单的对象.
The two statements are functionally equivalent, but the former is easier to read, particularly when the expression is more complicated than a simple object.
这篇关于谁能解释我为什么我们在拆箱过程中在大括号内写int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!