C# |
Copy Code
|
---|---|
public class Country { private static Random _random = new Random(); private static Country[] _countries = new Country[5] { new Country() { Name = "France", Capital = "Paris" }, new Country() { Name = "Japan", Capital = "Tokyo" }, new Country() { Name = "China", Capital = "Beijing" }, new Country() { Name = "Spain", Capital = "Madrid" }, new Country() { Name = "India", Capital = "New Delhi" } }; public string Name { get; set; } public string Capital { get; set; } public override string ToString() => $"{Name},{Capital}"; public static Country GetCountry() => _countries[_random.Next(0, _countries.Length - 1)]; public static Country GetCountry(int index) => _countries[index]; } |