C# 参数超出了真正简单数组的范围
我已经尽可能地简化了我正在编写的代码,以便让它只打印第一个单元格中的值。它一直在说: 参数超出范围“”mapArray.Star()(位于 Assets/Scripts/mapArray.cs32) 这是我目前的代码:C# 参数超出了真正简单数组的范围,c#,unity3d,C#,Unity3d,我已经尽可能地简化了我正在编写的代码,以便让它只打印第一个单元格中的值。它一直在说: 参数超出范围“”mapArray.Star()(位于 Assets/Scripts/mapArray.cs32) 这是我目前的代码: using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class mapArray : MonoBehaviour { p
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class mapArray : MonoBehaviour {
public class gridCell
{
public int theX { get; set; }
public gridCell(int xAx, int yAx, int TRVpen, int Ele, bool isOccupied)
{
this.theX = theX;
}
}
public void Start()
{
List<gridCell> cells = new List<gridCell>();
for (int i = 0; i < 288; i++)
{
int theX = i;
}
int theXvalue = cells[0].theX;
Debug.Log(theXvalue);
}
// Update is called once per frame
public void Update () {
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用制度;
公共类mapArray:MonoBehavior{
公共类网格单元
{
公共整数x{get;set;}
公共网格单元(int-xAx、int-yAx、int-TRVpen、int-Ele、bool-isocupied)
{
this.theX=theX;
}
}
公开作废开始()
{
列表单元格=新列表();
对于(int i=0;i<288;i++)
{
int theX=i;
}
int theXvalue=单元格[0];
Log(theXvalue);
}
//每帧调用一次更新
公共无效更新(){
}
}
列表单元格=新列表()代码>创建一个新数组,以便其中没有项。这就是为什么在执行int theXvalue=cells[0]时会出现此错误
for循环是否没有将项目放入数组中288个不同元素的x值中?循环只是将i
的值赋给x
变量。它不是cells
array的where设置值。在我添加的for循环中是Ok的:cells[i]=new?????(int theX=i);在访问cells集合项之前,您必须将gridCell对象添加到集合单元格中