我知道C#中没有指针,但如果你这样做: a = b; 和a和b都是数组,它们现在都指向相同的记忆 (改变一个改变另一个)。所以,它使它们看起来像是指针。 有人可以解释一下原因吗?谢谢。 Zytan
I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like pointers. Can someone please explain why? thanks. Zytan
推荐答案Zytan写道: Zytan wrote: 我知道C#中没有指针,但如果你这样做: a = b; 和a和b都是数组,他们现在都指向相同的记忆 (改变一个改变另一个)。所以,它使它们看起来像是指针。 有人可以解释一下原因吗?谢谢。 I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like pointers. Can someone please explain why? thanks.
这是一个参考,在某些方面确实非常类似于 C / C ++指针。 但你不能用它做指针操作。 Arne PS:你确实有C#中的指针不安全模式。
It is a reference, which indeed is very similar to a C/C++ pointer in some aspects. But you can not do pointer manipulation with it. Arne PS: You do have pointers in C# in unsafe mode.
它是一个引用,它确实非常类似于 It is a reference, which indeed is very similar to a C / C ++指针在某些方面。 但你不能用它做指针操作。 Arne PS:你在C#中有不安全模式的指针。 C/C++ pointer in some aspects. But you can not do pointer manipulation with it. Arne PS: You do have pointers in C# in unsafe mode.
好的。谢谢。 好的,我刚做了一些测试,当你将一个数组传递给一个 函数时,无论它是否为ref,当函数更改 数组的内容,当函数 返回时它们仍然会被更改。所以,它们就像指针一样。 Zytan
Ok. thanks. Ok, i just did some testing, and when you pass an array into a function, regardless if it is ref or not, when the function changes the array''s contents, they are still changed when the function returns. So, they are like pointers. Zytan
2月24日下午6:49, Zytan" < zytanlith ... @ yahoowrote: On Feb 24, 6:49 pm, "Zytan" <zytanlith...@yahoowrote: 这是一个参考,实际上非常类似于某些方面的 C / C ++指针。 It is a reference, which indeed is very similar to a C/C++ pointer in some aspects.
但你不能用它做指针操作。 But you can not do pointer manipulation with it.
Arne Arne
PS:你确实在C#中有指针不安全的模式。 PS: You do have pointers in C# in unsafe mode.
好的。谢谢。 好的,我刚做了一些测试,当你将一个数组传递给一个 函数时,无论它是否为ref,当函数更改 数组的内容,当函数 返回时它们仍然会被更改。所以,它们就像指针一样。 Zytan
Ok. thanks. Ok, i just did some testing, and when you pass an array into a function, regardless if it is ref or not, when the function changes the array''s contents, they are still changed when the function returns. So, they are like pointers. Zytan
是的,它们是。我认为它们是指针,因为对我来说这是一个熟悉的 成语。 正如Arne指出的那样,你不能做使用指针运算它们,虽然你永远不会注意到它,但不像指针引用 随时可以随着垃圾收集器压缩堆而改变 并移动物体。正如我所说,你不会注意到,因为 引用将始终引用同一个对象实例,即使 它并不总是指向到记忆中的同一个地方。
Yes, they are. I think of them as pointers, because that''s a familiar idiom for me. Howver, as Arne pointed out, you can''t do pointer arithmetic with them, and, although you''ll never notice it, unlike pointers references can change at any moment as the Garbage Collector compacts the heap and moves objects around. As I said, though, you won''t notice, because the reference will always refer to the same object instance, even if it doesn''t always point to the same place in memory.
更多推荐
数组=指针?
发布评论