public static void Main(string[] args) { Console.WriteLine("Hello Galaxy!"); Nebula nx1 = new Nebula("Exlporer", "NCC-61795", 30, 100, 7); Nebula nx2 = new Nebula("Exlporer", "NCC-61796", 30, 100, 12); Nebula nx3 = new Nebula("Exlporer", "NCC-61797", 30, 100, 9); Nebula[] ships = new Nebula[3]; ships[0] = nx1; ships[1] = nx2; ships[2] = nx3; Fleet FifthFleet = new Fleet(ships, "FifthFleet"); foreach (Nebula nx in ships) { Console.WriteLine(nx.ToString()); } // creating the delegate instance Fleet.NebulaCallback nxCallback = new Fleet.NebulaCallback(UpdateExpectancy); nxCallback += new Fleet.NebulaCallback(IncrementContractNumber); Console.WriteLine("Updating Nebula class life expectancy and Classification n"); FifthFleet.ProcessNebulaClassStarship(nxCallback); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
private static void IncrementContractNumber(Nebula nx) { int ContractNumber = 0; ContractNumber = nx.number; nx.number = ContractNumber += 3; Console.WriteLine("The starship {0}'s contract number is changed to {1}.", nx.classif, nx.number); }
private static void UpdateExpectancy(Nebula nx) { nx.expectancy *= 7; Console.WriteLine("The starship {0}'s life expectancy increased to {1} with crew of {2}", nx.classif, nx.expectancy, nx.crew); }
private static void ChangeClassificationToAssault(Nebula nx) { nx.classif = "Assault"; Console.WriteLine("The starship {0}'s life classification changed to {1}.", nx.classif); }