using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
// Using add method to add individual objects of Planet class.
var planets = new List<Planet>();
planets.Add(new Planet(){Id =1, Name ="Mercury"});
planets.Add(new Planet(){Id = 2, Name = "Venus"});
planets.Add(new Planet(){Id = 3, Name = "Earth"});
planets.Add(new Planet(){Id =4, Name ="Mars"});
// create a new Planet object, which contains Id and Name property. Set values for the properties one at a time—one per row.
var jupiter = new Planet();
jupiter.Id = 5;
jupiter.Name = "4 line: Jupiter";
planets.Add(jupiter);
//Above 4 lines vs below 1 line syntax. Same result
planets.Add(new Planet() { Id = 5, Name = "1 line: Jupiter" });
//Print values with ForEach loop
planets.ForEach(o => Console.WriteLine($"Planet Id = {o.Id} and Name = {o.Name}"));
}
public class Planet
public int Id { get; set; }
public string Name { get; set; }