Should I Dispose() DataSet and DataTable?

Here are a couple of discussions explaining why Dispose is not necessary for a DataSet. To Dispose or Not to Dispose ?: The Dispose method in DataSet exists ONLY because of side effect of inheritance– in other words, it doesn’t actually do anything useful in the finalization. Should Dispose be called on DataTable and DataSet … Read more

Why should you remove unnecessary C# using directives?

There are few reasons for removing unused using(s)/namespaces, besides coding preference: removing the unused using clauses in a project, can make the compilation faster because the compiler has fewer namespaces to look-up types to resolve. (this is especially true for C# 3.0 because of extension methods, where the compiler must search all namespaces for extension … Read more

What is the C# Using block and why should I use it? [duplicate]

If the type implements IDisposable, it automatically disposes that type. Given: public class SomeDisposableType : IDisposable { …implmentation details… } These are equivalent: SomeDisposableType t = new SomeDisposableType(); try { OperateOnType(t); } finally { if (t != null) { ((IDisposable)t).Dispose(); } } using (SomeDisposableType u = new SomeDisposableType()) { OperateOnType(u); } The second is easier … Read more

MySQL JOIN ON vs USING?

It is mostly syntactic sugar, but a couple differences are noteworthy: ON is the more general of the two. One can join tables ON a column, a set of columns and even a condition. For example: SELECT * FROM world.City JOIN world.Country ON (City.CountryCode = Country.Code) WHERE … USING is useful when both tables share … Read more

What are the uses of “using” in C#?

The reason for the using statement is to ensure that the object is disposed as soon as it goes out of scope, and it doesn’t require explicit code to ensure that this happens. As in Understanding the ‘using’ statement in C# (codeproject) and Using objects that implement IDisposable (microsoft), the C# compiler converts using (MyResource … Read more

Nested using statements in C#

The preferred way to do this is to only put an opening brace { after the last using statement, like this: using (StreamReader outFile = new StreamReader(outputFile.OpenRead())) using (StreamReader expFile = new StreamReader(expectedFile.OpenRead())) { ///… }

Do HttpClient and HttpClientHandler have to be disposed between requests?

The general consensus is that you do not (should not) need to dispose of HttpClient. Many people who are intimately involved in the way it works have stated this. See Darrel Miller’s blog post and a related SO post: HttpClient crawling results in memory leak for reference. I’d also strongly suggest that you read the … Read more

What is the best workaround for the WCF client `using` block issue?

Actually, although I blogged (see Luke’s answer), I think this is better than my IDisposable wrapper. Typical code: Service<IOrderService>.Use(orderService=> { orderService.PlaceOrder(request); }); (edit per comments) Since Use returns void, the easiest way to handle return values is via a captured variable: int newOrderId = 0; // need a value for definite assignment Service<IOrderService>.Use(orderService=> { newOrderId … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)