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
Syntax
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Jul 5, 2012, 2:52 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Jul 5, 2012, 2:38 AM EDT
So, that line is creating a new WebClient object (using its parameterless constructor) and then calling its instance method DownloadString.
Guest UserRank #4,868 · 321 reputationPosted Jul 5, 2012, 2:48 AM EDT
Guest UserRank #4,868 · 321 reputationPosted Jul 5, 2012, 2:54 AM EDT