Initialization of arrays in C#
Forums:
//Array of integer
int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 };
//Array of string
var gameList = new[] { "soccer", "hockey", "basketball" };
//Array of Employee class (another way)
var employees = new[] {
new Employee("Pavlov", "Anton"),
new Employee("Kirienko", "Elena")
};
class Employee {
public string FirstName { get; set; }
public string LastName { get; set; }
public Employee(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
- Log in to post comments