이 기능은 잘 작동합니다.목록 사용 Main() -
다른 클래스에있는 동적 값을 추가하면 main()에서 list0을 선언하고 싶습니다. 어떻게 ?
감사합니다.
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
public static void Main()
{
List<string> list0 = new List<string>();
list0.Add("A"); // Move to other class.
list0.Add("B"); // Move to other class.
string line0 = string.Join("/", list0.ToArray());
Console.WriteLine(line0);
Console.ReadLine();
}
}
======================================
업데이트] .
귀하의 도움을주십시오. 내 문제가 해결되었습니다. 더 이상의 질문.
using System;
using System.Collections.Generic;
using System.Text;
public class Program
{
public static void Main()
{
List<string> list0 = new List<string>();
list0.Add("A");
list0.Add("B");
otherClass oAdd = new otherClass();
oAdd.AddItem(list0);
string line0 = string.Join("/", list0.ToArray());
Console.WriteLine(line0);
Console.ReadLine();
}
}
public class otherClass
{
//error CS0117: 'otherClass' does not contain a definition for 'AddItem'
// If uncommented and switch to this line show the error above. I don't know why?
//public static void AddItems(IList<string> list0)
public void AddItem(IList<string> list0)
{
list0.Add("C");
list0.Add("D");
}
}
다른 문제가 발견되었습니다. 감사.
좀 더 구체적으로 말씀해 주시겠습니까? 너 정확히 뭘 하려구? 추가 작업을 목록을 매개 변수로받는 별도의 메서드에 있어야합니까? –
목록을 속성으로 만들고 다른 클래스에서 설정하려고합니까? –
@ 모세 예, 네 말대로. 추가 작업을 별도의 클래스 (메서드)에 넣고 목록을 매개 변수로 받아야합니다. 감사. –