Should I Dispose() DataSet and DataTable?

DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods. However, from what I’ve read so far, DataSet and DataTable don’t actually have any unmanaged resources, so Dispose() doesn’t actually do much. Plus, I can’t just use using(DataSet myDataSet…) because DataSet has a collection of DataTables. So, to … Read more

MySQL JOIN ON vs USING?

In a MySQL JOIN, what is the difference between ON and USING()? As far as I can tell, USING() is just more convenient syntax, whereas ON allows a little more flexibility when the column names are not identical. However, that difference is so minor, you’d think they’d just do away with USING(). Is there more … Read more

Nested using statements in C#

I am working on a project. I have to compare the contents of two files and see if they match each other precisely. Before a lot of error-checking and validation, my first draft is: DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + “\\TestArea\\”); FileInfo[] files = di.GetFiles(filename + “.*”); FileInfo outputFile = files.Where(f => f.Extension == “.out”).Single<FileInfo>(); … Read more

Do HttpClient and HttpClientHandler have to be disposed between requests?

System.Net.Http.HttpClient and System.Net.Http.HttpClientHandler in .NET Framework 4.5 implement IDisposable (via System.Net.Http.HttpMessageInvoker). The using statement documentation says: As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. This answer uses this pattern: var baseAddress = new Uri(“http://example.com”); var cookieContainer = new CookieContainer(); using (var handler = new … Read more

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

I like instantiating my WCF service clients within a using block as it’s pretty much the standard way to use resources that implement IDisposable: using (var client = new SomeWCFServiceClient()) { //Do something with the client } But, as noted in this MSDN article, wrapping a WCF client in a using block could mask any … Read more