Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created July 22, 2017 08:03
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/b8dc9eb60e1165264e7b2db2abe70624 to your computer and use it in GitHub Desktop.
Save christiannagel/b8dc9eb60e1165264e7b2db2abe70624 to your computer and use it in GitHub Desktop.
Using a Lambda Expression within a Method
static void AsynchronousPattern()
{
WebRequest request = WebRequest.Create(url);
IAsyncResult result = request.BeginGetResponse(ar =>
{
using (WebResponse response = request.EndGetResponse(ar))
{
Stream stream = response.GetResponseStream();
var reader = new StreamReader(stream);
string content = reader.ReadToEnd();
Console.WriteLine(content.Substring(0, 100));
Console.WriteLine();
}
}, null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment