This problem is very similar to this question, this question, this question (same error, different source class), and this question (same error, different reason).
After compiling my programs in a project to check for errors, I got the following CS1061 error:
Entity.cs(291,24): error CS1061: '
List<Entity>
' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'List<Entity>
' could be found (are you missing a using directive or an assembly reference?)
Entity.cs is the name of the file where the error occurred, and said error occurs in the Load() function, shown below:
public void Load(){
/*
Try to spawn the entity.
If there are too many entities
on-screen, unload any special
effect entities.
If that fails, produce an error message
*/
try{
if(EntitiesArray.Count >= EntitiesOnScreenCap){
if(this.Type == EntityType.SpecialEffect)
Unload();
else
throw null;
}else
//Place the entity in the first available slot in the array
for(int i = 0; i < EntitiesArray.Capacity; i++)
if(EntitiesArray.Item[i] == NullEntity)
EntitiesArray.Item[i] = this;
}catch(Exception exc){
throw new LoadException("Failed to load entity.");
}
}
The error happens on these lines (lines 291 & 292):
if(EntitiesArray.Item[i] == NullEntity)
EntitiesArray.Item[i] = this;
NullEntity
is a field of type Entity
, and this
is also of type Entity
.
EntitesArray
is a List<Entity>
and, therefore, should have an Item[]
property, according to the MSDN documentation here.
Entity
does not have a method or array named Item
.
Declaration at beginning of class Entity
:
public static List<Entity> EntitiesArray;
Instantiation in a method in Entity
that is guaranteed to run only once:
EntitiesArray = new List<Entity>(EntitiesOnScreenCap);
Field EntitiesOnScreenCap
is an int
equal to 200.
This is included at the highest scope (before the namespace), so there should not be any problems regarding this:
using System.Collections.Generic;
What is causing this CS1061 error, and how can I fix it?