public void CanCallMethodWithOptionalArguments() { var detective = new Detective(); // If the caller provides an argument for any one of a succession of optional parameters, it must // provide arguments for all preceding optional parameters. // The following line will not compile //var results = detective.FindSuspect("Fraud", ,20); var results = detective.FindSuspect("Fraud", DateTime.Now); Assert.AreEqual(50, results); }
public void CanCallMethodWithNamedArguments() { var detective = new Detective(); // Named arguments can be supplied for the parameters in either order. bool mysterySolved = detective.SolveMystery(suspect: "Poirot", crime: "Murder"); Assert.IsTrue(mysterySolved); // Positional arguments cannot follow named arguments. // The following statement causes a compiler error. //mysterySolved = detective.SolveMystery(crime:"Murder", "Poirot"); // Named arguments can follow positional arguments. mysterySolved = detective.SolveMystery("Murder", suspect:"Poirot"); Assert.IsTrue(mysterySolved); }