Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将一个项目从一个列表添加到另一个列表_C#_List - Fatal编程技术网

C# 如何将一个项目从一个列表添加到另一个列表

C# 如何将一个项目从一个列表添加到另一个列表,c#,list,C#,List,我有一个名为“EncTypeOpportunities”的列表,我想把项目“Land”交给另一个列表 public static List<Encounter> enctypechances = new List<Encounter>(); Encounter Land = new Encounter(20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1); publicstaticlist=newlist(); 遭遇陆地=新遭遇(20,20

我有一个名为“EncTypeOpportunities”的列表,我想把项目“Land”交给另一个列表

public static List<Encounter> enctypechances = new List<Encounter>();
Encounter Land = new Encounter(20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1);
publicstaticlist=newlist();
遭遇陆地=新遭遇(20,20,10,10,10,10,5,5,4,4,1,1);
这里是我想添加“土地”项目的地方

List enctypes=new List();
无效开始(){
添加(??);
}

Land
必须在
start()范围内可见。您必须在方法中声明它,将它作为参数传递给方法,或者确保它在类中可见


不过,正如其他人所评论的,您可能应该向我们展示更多代码以获得更具体的答案。

enctypes.Add(Land)
?Icepickle说它在当前上下文中不可用。那么我想您需要更改
Land
的范围。您没有向我们展示足够的代码来了解作用域是什么,但您可以从错误消息中轻松判断它是错误的。我给了Land
public static
,并从另一个类调用了enctypes.Add(Land)。再也不需要enctypeschanes了。谢谢你的帮助。我给了Land
public static
,并从另一个类调用了
enctypes.Add(Land)。再也不需要enctypeschanes了。谢谢你的帮助。
List<Encounter> enctypes = new List<Encounter>();

void Start () {
    enctypes.Add( ??? );
}