我有这个代码示例。它通过引用传递变量,但它不应该(我不认为)。我认为它默认通过引用传递变量。我不确定要搜索什么才能找到关于此的文档。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CS_example_2
{
class Program
{
static void Main(string[] args)
{
int result = setResult();
List<string> namesResult = new List<string>();
setResultAr(namesResult);
for (int i = 0; i < namesResult.Count; i += 1)
{
if (i == result)
{
System.Console.WriteLine("Result is " + namesResult[i]);
break;
}
}
System.Console.ReadKey();
}
static int setResult()
{
int result = 3;
return result;
}
static void setResultAr(List<string> namesResult)
{
List<string> res_array = new List<string>() { "item1", "item2", "item3, "item4", "item5" };
foreach (string s in res_array)
{
namesResult.Add(s);
}
}
}
}