이 코드 샘플이 있습니다. 그것은 참조로 변수를 전달하지만 shouldn (나는 생각하지 않는다). 변수를 참조로 전달하는 것은 기본값이라고 생각합니다. 이것에 대한 문서를 찾기 위해 정확히 무엇을 검색해야할지 모르겠습니다.자동으로 참조로 변수 전달
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);
}
}
}
}
무엇이 질문입니까? – lockstock
이 작업을 설명하는 일부 MSDN 설명서를 찾고 싶습니다. – Sugitime
C#은 명시 적으로 참조를 전달하지 않는 한 항상 매개 변수 'ByVal'을 전달합니다. –