Start with the name, ".NET". What were they referring to when they chose that name very carefully? They were referring to the web.
C# 5.0? Take a look at this example code from the MSDN blog which is "showing off" the new features of C# 5.0. (It was formatted this way with no indentation on the blog). This example, not by coincidence, demonstrates how .NET interfaces with the web.
private async void
btnTest_Click(object sender, EventArgs e)
{
var request = WebRequest.Create(txtUrl.Text.Trim());
var content = new MemoryStream();
Task<WebResponse> responseTask = request.GetResponseAsync();
using (var response = await responseTask)
{
using (var
responseStream = response.GetResponseStream())
{
Task copyTask = responseStream.CopyToAsync(content);
//await operator to supends the excution of the method until the task is completed. In the meantime,
the control is returned the UI thread.
await copyTask;
}
}
txtResult.Text = content.Length.ToString();
}
What does that code do? It works behind a form running on the desktop, where you press a button to do an async HTTP request and display the content length of the response.
First of all, why would I want to create an application that runs on the desktop, rather than build a web application that I can show to people with a link? Especially
If I were going to do the same thing with a web application then I would probably do something like this in CoffeeScript:
I'm sorry, but I don't see C# as being the most damn awesome all-around language. I like CoffeeScript, or maybe even better, LiveScript (http://livescript.net). Or failing that, plain-old JavaScript.
For one, you're criticizing a web API here and not the C# language-- and you've failed to even do that convincingly since it's an intentionally verbose example using an outdated API.
res.Text = (await new HtppClient().GetStringAsync(url.Text)).Length.ToString();
> First of all, why would I want to create an application that runs on the desktop, rather than build a web application that I can show to people with a link? Especially
To take proper advantage of the hardware and provide proper integration with the operating system.
That's not a fantastic code sample, but its purpose is to show off the async / await keyword. There's no point in criticizing it for not being a web app... I do wish, however, that MSDN blogs put more focus on good, idiomatic C#, formatted properly, but they so often come up short, only doing one thing adequately while failing at all others.
C# 5.0? Take a look at this example code from the MSDN blog which is "showing off" the new features of C# 5.0. (It was formatted this way with no indentation on the blog). This example, not by coincidence, demonstrates how .NET interfaces with the web.
What does that code do? It works behind a form running on the desktop, where you press a button to do an async HTTP request and display the content length of the response.First of all, why would I want to create an application that runs on the desktop, rather than build a web application that I can show to people with a link? Especially
If I were going to do the same thing with a web application then I would probably do something like this in CoffeeScript:
I'm sorry, but I don't see C# as being the most damn awesome all-around language. I like CoffeeScript, or maybe even better, LiveScript (http://livescript.net). Or failing that, plain-old JavaScript.