Having for example such enumerations:
public enum Gender
{
Femele,
Male,
...
}
public enum Ethnic
{
African,
Asian,
European,
...
}
And this class:
public class Person
{
public string Name { get; set; }
public Gender Gender { get; set; }
public Ethnic Ethnic { get; set; }
}
You can use this loop:
using System.Linq;
using System.Collections.Generic;
int peopleCount = 587;
List<Person> people = new List<Person>();
foreach ( var index in Enumerable.Range(1, peopleCount) )
people.Add(new Person());
Select can also be used as exposed by @lrpe.
The number can be set as a const or a static or an instance member that can be readonly or modifiable:
public const int PeopleCount = 587;
static public int PeopleCount { get; } = 587;
public int PeopleCount { get; set; } = 587;
The same for the object:
private readonly List<Person> People = new List<Person>();
Here it is a composite:
Understanding the Aggregation, Association, Composition
What is the difference between association, aggregation and composition?
Initializing members of a person depend on more details about your design and goal: you will probably set them via a user window or from a data file.
A default name can be assigned in the loop:
foreach ( var index in Enumerable.Range(1, PeopleCount) )
People.Add(new Person { Name = $"Person {index}" });
Or using Select:
People.AddRange(Enumerable.Range(1, PeopleCount)
.Select(index => new Person { Name = $"Person {index}" }));
People = Enumerable.Range(1, PeopleCount)
.Select(index => new Person { Name = $"Person {index}" })
.ToList();
Perhaps you may prefer or want to use in addition to name an ID:
public class Person
{
public Guid Id { get; } = Guid.NewGuid();
public string Name { get; set; }
public Gender Gender { get; set; }
public Ethnic Ethnic { get; set; }
public int Age { get; set; }
}
If setters are not needed set them private or init only, and also use real fields if needed like in your original code.
How do you like your primary keys?
How generate unique Integers based on GUIDs
Can using Ticks of DateTime.Now can generate duplicates unique identifiers?
Guid vs INT - Which is better as a primary key?
Universally unique identifier