using

Visual Studio Recommending to Simplify Using Command

会有一股神秘感。 提交于 2021-02-04 21:19:30
问题 I've noticed since updating Visual Studio that it is now recommending to simplify my MySQL using statements. It wants to change this: using (MySqlCommand command = new MySqlCommand(sql_string, connection)) { command.Parameters.AddWithValue("@id", id); MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); business = new Business() { Id = int.Parse(reader["id"].ToString()), Name = reader["name"].ToString(), }; reader.Dispose(); } } Into this: using MySqlCommand

Visual Studio Recommending to Simplify Using Command

半腔热情 提交于 2021-02-04 21:19:13
问题 I've noticed since updating Visual Studio that it is now recommending to simplify my MySQL using statements. It wants to change this: using (MySqlCommand command = new MySqlCommand(sql_string, connection)) { command.Parameters.AddWithValue("@id", id); MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); business = new Business() { Id = int.Parse(reader["id"].ToString()), Name = reader["name"].ToString(), }; reader.Dispose(); } } Into this: using MySqlCommand

Multiple using block, is this code safe?

99封情书 提交于 2021-01-29 03:11:36
问题 Code snippet is as follows public static string ToCompressedBase64(this string text) { using (var memoryStream = new MemoryStream()) { using (var gZipOutputStream = new GZipStream(memoryStream, CompressionMode.Compress)) { using (var streamWriter = new StreamWriter(gZipOutputStream)) { streamWriter.Write(text); } } return Convert.ToBase64String(memoryStream.ToArray()); } } As far as I know, if class contains field which is IDisposable then It should implement IDisposable itself and take care

C++ template alias (using) in specific places

旧街凉风 提交于 2021-01-27 04:34:29
问题 I need to use type aliases via using (or any other method) in situations like this: template <class T> typename std::enable_if< /*HERE*/>::value f (...) {}; Where I wrote HERE there are long and more than one types defined inside structures, and instead of writing typename <very long templated struct dependent on T>::type I want to write a shortcut. And I encountered this in more situations like template specializations and suffix return type syntax. So Is there any way of using using (no pun

Is a nested alias template that redeclares the same name valid?

给你一囗甜甜゛ 提交于 2021-01-07 03:11:18
问题 Given some class template: template <typename> struct T {}; a type alias declaration that changes the meaning of the name T like this is not allowed: struct S { using T = T<void>; // ill formed no diagnostic required }; There is an explanation given here as to why this is the case, and it also suggests a fix: struct S { using T = ::T<void>; // ok }; So my question is, how about an alias template as in this case? struct S { template <typename> using T = T<void>; // ok ? }; Is this well formed?

Is a nested alias template that redeclares the same name valid?

只谈情不闲聊 提交于 2021-01-07 03:10:19
问题 Given some class template: template <typename> struct T {}; a type alias declaration that changes the meaning of the name T like this is not allowed: struct S { using T = T<void>; // ill formed no diagnostic required }; There is an explanation given here as to why this is the case, and it also suggests a fix: struct S { using T = ::T<void>; // ok }; So my question is, how about an alias template as in this case? struct S { template <typename> using T = T<void>; // ok ? }; Is this well formed?

Exception handling (contradicting documentation / try-finally vs. using)

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-08 07:07:58
问题 I thought I had understood how exception handling in C# works. Re-reading the documentation for fun and self-confidence, I have run into problems: This document claims that the following two code snippets are equivalent, even more, that the first one is translated to the latter one at compile time. using (Font font1 = new Font("Arial", 10.0f)) { byte charset = font1.GdiCharSet; } and { Font font1 = new Font("Arial", 10.0f); try { byte charset = font1.GdiCharSet; } finally { if (font1 != null)

Exception handling (contradicting documentation / try-finally vs. using)

安稳与你 提交于 2020-12-08 07:05:41
问题 I thought I had understood how exception handling in C# works. Re-reading the documentation for fun and self-confidence, I have run into problems: This document claims that the following two code snippets are equivalent, even more, that the first one is translated to the latter one at compile time. using (Font font1 = new Font("Arial", 10.0f)) { byte charset = font1.GdiCharSet; } and { Font font1 = new Font("Arial", 10.0f); try { byte charset = font1.GdiCharSet; } finally { if (font1 != null)

Exception handling (contradicting documentation / try-finally vs. using)

Deadly 提交于 2020-12-08 07:05:13
问题 I thought I had understood how exception handling in C# works. Re-reading the documentation for fun and self-confidence, I have run into problems: This document claims that the following two code snippets are equivalent, even more, that the first one is translated to the latter one at compile time. using (Font font1 = new Font("Arial", 10.0f)) { byte charset = font1.GdiCharSet; } and { Font font1 = new Font("Arial", 10.0f); try { byte charset = font1.GdiCharSet; } finally { if (font1 != null)