为什么我们需要在C#中装箱和拆箱?
我知道拳击和拆箱是什么,但我无法理解它的实际用途.我应该在哪里以及在哪里使用它?
short s = 25;
object objshort = s; //Boxing
short anothershort = (short)objshort; //Unboxing
Run Code Online (Sandbox Code Playgroud) 在下面的代码中使用加号时,将创建多少个String对象?
String result = "1" + "2" + "3" + "4";
Run Code Online (Sandbox Code Playgroud)
如果它如下,我会说三个String对象:"1","2","12".
String result = "1" + "2";
Run Code Online (Sandbox Code Playgroud)
我也知道String对象被缓存在String Intern Pool/Table中以提高性能,但这不是问题.