I'm practicing C# and in an API object it doesn't let me add a new data to the array
error CS0021: Cannot apply indexing with [] to an expression of type 'Array'
public class UsersController : ControllerBase
{
private Array people = new object[] {
new Person { id=1, Name="Ana", age=24 },
new Person { id=2, Name="Joseph", age=20 }
};
[HttpGet("users")]
public ActionResult<Person> GetAll()
{
return Ok(
this.people
);
}
[HttpGet("users/{id}")]
public ActionResult<Person> Get(int id)
{
var pipe = new searchClient();
var data = this.people;
var looking = pipe.getClient(id, data);
return Ok(
looking
);
}
[HttpPost("add_user")]
public void AddClient(Object data)
{
for (int x = 0; x < this.people.GetLength(0); x++) {
this.people[x] = data; // Error
}
}
}
I'm learning C#, I don't understand what I'm missing