Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created July 22, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/59506b717fbe1b3afa6987899e8e1fe6 to your computer and use it in GitHub Desktop.
Save christiannagel/59506b717fbe1b3afa6987899e8e1fe6 to your computer and use it in GitHub Desktop.
Local Function instead of a Lambda expression
private static void AsynchronousPattern()
{
WebRequest request = WebRequest.Create(url);
IAsyncResult result = request.BeginGetResponse(ReadResponse, null);
void ReadResponse(IAsyncResult ar)
{
using (WebResponse response = request.EndGetResponse(ar))
{
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
Console.WriteLine(content.Substring(0, 100));
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment