Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using-keyword-blog-post
{
StreamReader sr = new StreamReader(filename);
try
{
String text = sr.ReadToEnd();
return text;
}
finally
{
if (sr != null)
((IDisposable)sr).Dispose();
}
}
public string ReadFromFile(string filename)
{
using (StreamReader sr = new StreamReader(filename))
{
String text = sr.ReadToEnd();
return text;
}
}
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
You can’t perform that action at this time.