- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我指的是本网站上的代码:http://www.dotnetperls.com/fisher-yates-shuffle
public static void Shuffle<T>(T[] array)
{
var random = _random;
for (int i = array.Length; i > 1; i--)
{
// Pick random element to swap.
int j = random.Next(i); // 0 <= j <= i-1
// Swap.
T tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
}
为什么Shuffle<T>(T[] array)
中的数组不是必须要返回吗?我想为了改变一个变量的传入值,并让它影响调用它的方法中的变量,你必须使用 ref
.那么为什么没有ref
呢?正在使用?
最佳答案
来自 http://msdn.microsoft.com/en-us/magazine/cc301755.aspx
Arrays are mechanisms that allow you to treat several items as a single collection. The Microsoft® .NET Common Language Runtime (CLR) supports single-dimensional arrays, multidimensional arrays, and jagged arrays (arrays of arrays). All array types are implicitly derived from System.Array, which itself is derived from System.Object. This means that all arrays are always reference types which are allocated on the managed heap, and your app's variable contains a reference to the array and not the array itself.
因为它们是引用类型,所以所讨论的函数正在接收对数组的引用。
关于c# - 为什么不必返回此数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438516/
我是一名优秀的程序员,十分优秀!