From 8b62c313b1e95428adb363425d35456e726e2d7f Mon Sep 17 00:00:00 2001 From: olwaro Date: Sun, 16 Feb 2014 22:00:33 +0100 Subject: [PATCH 1/2] Adds an example of 'using' statement --- csharp.html.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/csharp.html.markdown b/csharp.html.markdown index dad0c26b..e240bf86 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -30,6 +30,7 @@ using System.Linq; using System.Linq.Expressions; using System.Net; using System.Threading.Tasks; +using System.IO; // defines scope to organize code into "packages" namespace Learning @@ -434,6 +435,17 @@ on a new line! ""Wow!"", the masses cried"; Func square = (x) => x * x; // Last T item is the return value Console.WriteLine(square(3)); // 9 + // DISPOSABLE RESSOURCES MANAGEMENT - let you handle unmanaged resources easily + // Most of objects that access unmanaged resources (file handle, device contexts, etc.) + // implement the IDisposable interface. The using statement takes care of + // cleaning those IDisposable objects for you. + using (StreamWriter writer = new StreamWriter("log.txt")) + { + writer.WriteLine("Nothing suspicious here"); + // At the end of scope, ressources will be released. + // Even if an exception is thrown. + } + // PARALLEL FRAMEWORK // http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx var websites = new string[] { From f6032ba1906f51a59ecc17d24864a6f56d100c14 Mon Sep 17 00:00:00 2001 From: olwaro Date: Mon, 17 Feb 2014 10:43:18 +0100 Subject: [PATCH 2/2] Fixes typos --- csharp.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp.html.markdown b/csharp.html.markdown index e240bf86..12bdf168 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -435,14 +435,14 @@ on a new line! ""Wow!"", the masses cried"; Func square = (x) => x * x; // Last T item is the return value Console.WriteLine(square(3)); // 9 - // DISPOSABLE RESSOURCES MANAGEMENT - let you handle unmanaged resources easily + // DISPOSABLE RESSOURCES MANAGEMENT - let you handle unmanaged resources easily. // Most of objects that access unmanaged resources (file handle, device contexts, etc.) // implement the IDisposable interface. The using statement takes care of // cleaning those IDisposable objects for you. using (StreamWriter writer = new StreamWriter("log.txt")) { writer.WriteLine("Nothing suspicious here"); - // At the end of scope, ressources will be released. + // At the end of scope, resources will be released. // Even if an exception is thrown. }