Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void CreatePeopleConstructors()
- {
- Console.WriteLine("Enter person parameters or leave blank");
- string input = Console.ReadLine();
- List<Person> persons = new List<Person>();
- while (input != "end")
- {
- string[] inputArgs = input.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- if (inputArgs.Length == 0)
- {
- persons.Add(new Person());
- }
- else if (inputArgs.Length == 1)
- {
- int n;
- bool isNumeric = int.TryParse(inputArgs[0], out n);
- if (isNumeric)
- {
- persons.Add(new Person(n));
- }
- else
- {
- persons.Add(new Person(inputArgs[0]));
- }
- }
- else
- {
- string name = inputArgs[0];
- int age = int.Parse(inputArgs[1]);
- persons.Add(new Person { Name = name, Age = age });
- }
- Console.WriteLine("Enter *end* to stop adding and print out the results or add more info.");
- input = Console.ReadLine();
- }
- foreach (var p in persons)
- {
- Console.WriteLine($"{p.Name} {p.Age}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement