static void Main(string[] args) { var defaultSettings = new CustomWebClient().Settings; var webClientReplacedSettings = new CustomWebClient { Settings = new CustomWebClientSettings { Encoding = "UTF-8", Method = "POST" } }; Console.WriteLine("Default settings:"); Console.WriteLine(defaultSettings.Dump()); PrintComparedSettings(defaultSettings, webClientReplacedSettings.Settings); Console.WriteLine(); // of course we can just set properties Encoding and Method without creating Settings object var webClientDotOperator = new CustomWebClient(); webClientDotOperator.Settings.Encoding = "UTF-8"; webClientDotOperator.Settings.Method = "POST"; // but there is a cooler syntax for that Console.WriteLine("Settings nested properties using nested object initializer"); webClientDotOperator = new CustomWebClient { Settings = { Encoding = "UTF-8", Method = "POST" } }; PrintComparedSettings(defaultSettings, webClientDotOperator.Settings); Console.ReadKey(); }
static void Main(string[] args) { var defaultSettings = new CustomWebClient().Settings; var webClientReplacedSettings = new CustomWebClient { Settings = new CustomWebClientSettings { Encoding = "UTF-8", Method = "POST" } }; Console.WriteLine("Default settings:"); Console.WriteLine(defaultSettings.Dump()); PrintComparedSettings(defaultSettings, webClientReplacedSettings.Settings); Console.WriteLine(); // of course we can just set properties Encoding and Method without creating Settings object var webClientDotOperator = new CustomWebClient(); webClientDotOperator.Settings.Encoding = "UTF-8"; webClientDotOperator.Settings.Method = "POST"; // but there is a cooler syntax for that Console.WriteLine("Settings nested properties using nested object initializer"); webClientDotOperator = new CustomWebClient { Settings = { Encoding = "UTF-8", Method = "POST" } }; PrintComparedSettings(defaultSettings, webClientDotOperator.Settings); Console.ReadKey(); }