Last active
September 22, 2017 14:36
-
-
Save GSoster/caf4a73995647f434e87b67fedfd56a4 to your computer and use it in GitHub Desktop.
using-keyword-blog-post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
StreamReader sr = new StreamReader(filename); | |
try | |
{ | |
String text = sr.ReadToEnd(); | |
return text; | |
} | |
finally | |
{ | |
if (sr != null) | |
((IDisposable)sr).Dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string ReadFromFile(string filename) | |
{ | |
using (StreamReader sr = new StreamReader(filename)) | |
{ | |
String text = sr.ReadToEnd(); | |
return text; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Product GetProductById(int productId) | |
{ | |
using (ProductContext db = new ProductContext) | |
{ | |
return db.Products.SingleOrDefault(p => p.Id == productId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment