Hi
Given the following statement:-
new WebClient().DownloadString("http://www.foo.com");
I require help in understand the syntax's
WebClient()
// This is a class but has a parenthesis as if it were a method.
.DownloadString("http://www.foo.com");
// This method is not Static OR an Extension method but is accessed with the dot notation as if it were Static or an Extension.
Regards
Steven
Loading
VulpesPosted Jul 5, 2012, 6:52 AM
The line is equivalent to these two lines:
WebClient wc = new WebClient();
wc.DownloadString("http://www.foo.com");
However, if you don't need to refer to the 'wc' variable elsewhere, you can avoid declaring it at all by combining these two lines into one.
Guest UserPosted Jul 5, 2012, 6:54 AM
Guest UserPosted Jul 5, 2012, 6:48 AM
VulpesPosted Jul 5, 2012, 6:38 AM
So, that line is creating a new WebClient object (using its parameterless constructor) and then calling its instance method DownloadString.