这不太清楚......我得到了它,但现在我又失去了它的结构/课程 [英] This is not too clear... thougt i got it but now i lost it againstruct/class
问题描述
很烦人......不像CI想的那样......我得到了它但是没有...是什么? />
我错过了...
public struct S
{public int i;}
公共课C
{public int i;}
class program
{
static void Main(string [] args){
S a = new S();
C c = new C();
ai = 5;
ci = 5;
S b = a;
C d = c;
ai = 6;
ci = 6;
Console.WriteLine(bi); // 5呵呵?
Console.WriteLine(d.i); // 6 yess ....
Console.ReadLine();
}
}
// CY
12月18日上午10点49分,christ ... @ gmail.com写道:
通过Jo读取yoda的内容我认为...
烦人...不喜欢CI认为...
这肯定不像C.
thougth我得到了但是没有......什么我错过了...
当你执行S b = a;
时,b是a中数据的副本,其中是实际的整数。
更改ai的值不会改变bi的值
执行C d = c时;
然后(再次)d是b中数据的副本,这只是对象的参考
。两个变量然后引用同一个对象,所以当你改变c.i时,你可以看到。也可以通过d.i进行更改。
Jon
执行C d = c时;
然后(再次)d是b中数据的副本,这只是该对象的参考资料
。两个变量然后引用同一个对象,所以当你改变c.i时,你可以看到。通过di也可以改变。
Jon
好吧,我觉得我明白了......混淆什么是引用和什么是新的
copys ...
在 http://rapidapplicationdevelopment.b...sing-in-c.html
让我觉得它在复制/参考之间神奇地切换......
// CY
< ch *** **** @ gmail.com写道:
当你执行C d = c;
然后(再次)d是b中数据的副本,它只是对象的一个参考
。两个变量然后引用同一个对象,所以当你改变c.i时,你可以看到。也可以通过di来改变。
Jon
好吧,我觉得我明白了...混淆什么是引用和什么是新的
copys ...
在 http://rapidapplicationdevelopment.blogspot.com/
2007/01 / parameter-passing-in-c.html
让我觉得它在复制/参考之间神奇地切换...
不 - 重要的是赋值*总是*复制值
$变量的b $ b;你只需要了解
变量的值是实际数据,还是只是一个参考。一旦点击
生活变得容易多了:)
-
Jon Skeet - < sk * **@pobox.com>
http://www.pobox.com/ ~Sibet 博客: http://www.msmvps.com/jon。双向飞碟
英国的世界级.NET培训: http: //iterativetraining.co.uk
read something on yoda by Jo I think...
annoying ... not like C I think... thougth I got it but no... what am
I missing...
public struct S
{ public int i;}
public class C
{ public int i;}
class Program
{
static void Main(string[] args){
S a = new S();
C c = new C();
a.i=5;
c.i = 5;
S b = a;
C d = c;
a.i=6;
c.i = 6;
Console.WriteLine(b.i); //5 huh?
Console.WriteLine(d.i); // 6 yess....
Console.ReadLine();
}
}
//CY
On Dec 18, 10:49 am, christ...@gmail.com wrote:read something on yoda by Jo I think...
annoying ... not like C I think...It''s certainly not like C.
thougth I got it but no... what am I missing...When you execute S b = a;
then b is a copy of the data in a, which is the actual integer.
Changing the value of a.i doesn''t change the value of b.i.
When you execute C d = c;
then (again) d is a copy of the data in b, which is just a reference
to the object. Both variables then refer to the same object, so when
you change c.i, you can "see" that change via d.i as well.
Jon
When you execute C d = c;then (again) d is a copy of the data in b, which is just a reference
to the object. Both variables then refer to the same object, so when
you change c.i, you can "see" that change via d.i as well.
JonOK, think I got it... confusing what are references and what are new
copys...
looking at #3 in http://rapidapplicationdevelopment.b...sing-in-c.html
made me think it switched between copy/ref magically...
//CY
<ch*******@gmail.comwrote:When you execute C d = c;
then (again) d is a copy of the data in b, which is just a reference
to the object. Both variables then refer to the same object, so when
you change c.i, you can "see" that change via d.i as well.
Jon
OK, think I got it... confusing what are references and what are new
copys...
looking at #3 in http://rapidapplicationdevelopment.blogspot.com/
2007/01/parameter-passing-in-c.html
made me think it switched between copy/ref magically...Nope - the important thing is that assignment *always* copies the value
of the variable; you just need to understand whether the value of the
variable is the actual data, or just a reference. Once that "clicks"
life becomes a lot easier :)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
这篇关于这不太清楚......我得到了它,但现在我又失去了它的结构/课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!