This example is confusing, although technically correct. In the real world, this βas isβ pattern does not matter.
They do not even return SqlConnection to the calling code.
Therefore, "they were concise with the code," as you said.
In a real world scenario, you might have this method
private static SqlConnection OpenSqlConnection(string connectionString) { SqlConnection connection = new SqlConnection(connectionString) connection.Open(); return connection; }
and then use it in your code (although there is not much of it)
using(SqlConnection cnn = OpenSqlConnection(connectionString)) {
of course, the using statement hides all the work in order to catch exceptions and close / delete everything this way, while technically speaking, exceptions are handled, in fact you don't get any hints if something fails.
Steve
source share