using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Test
{
class Program
{
public static void DobuNums(ref int[] nums)
{
for (int i = 0; i < nums.Length; i++)
{
nums[i] = nums[i] * 2;
}
nums = new int[] { 7, 8, 9 }; //若注释这一行结果又是什么
}
int[] nums = new int[] {2,3,4};
public static void Main(string[] args)
{
int[] nums = new int[] { 1, 2, 3 };
int[] copyNums = nums;
object cloneNums = nums.Clone();
string numsStr = null;
for (int i = 0; i < nums.Length; i++)
{
numsStr += nums[i];
}
numsStr += "\n";
DobuNums(ref nums);
for (int i = 0; i < nums.Length; i++)
{
numsStr += nums[i];
}
numsStr += "\n";
for (int i = 0; i < copyNums.Length; i++)
{
numsStr += copyNums[i];
}
numsStr += "\n";
if (ReferenceEquals(nums, copyNums))
{
Console.WriteLine(numsStr);
Console.WriteLine("nums ReferenceEquals copyNums");
}
else
{
Console.WriteLine(numsStr);
Console.WriteLine("nums is not ReferenceEquals copyNums");
}
Console.ReadKey();
}
}
}
这是笔试的一道题,供大家参考。