summaryrefslogtreecommitdiffhomepage
path: root/csharp.html.markdown
diff options
context:
space:
mode:
authorNami-Doc <vendethiel@hotmail.fr>2014-02-17 13:59:34 +0100
committerNami-Doc <vendethiel@hotmail.fr>2014-02-17 13:59:34 +0100
commit5ff5f6c0d864f6ec300f14e49119d4e259dbf4be (patch)
tree575fde14bebc4512eb2bd3a6b4ea4f3e8cfd128d /csharp.html.markdown
parent56e6f0133d298051e864fcd0c7c0d834edcc4d7c (diff)
parentf6032ba1906f51a59ecc17d24864a6f56d100c14 (diff)
Merge pull request #535 from Olwaro/loan_pattern
[csharp/en] Adds example of 'using' statement for resources handling
Diffstat (limited to 'csharp.html.markdown')
-rw-r--r--csharp.html.markdown12
1 files changed, 12 insertions, 0 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 3a870b7a..81b50e08 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<int, int> 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, resources 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[] {