The using statement in C# can also be used to ensure that the resources are automatically cleaned before the using block exits.
One of the criteria of the Using statement is that the items being created in the using statement must implement IDisposable interface.
For example, you can use the using block to open the SQL Connection, retrieve the data.
Using block for SQLConnection in C#
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace AbundantCode { internal class Program { //Using block for SQLConnection in C# private static void Main(string[] args) { // var AbundantCodeVersions = new string[] { "AbundantCode v1", "AbundantCode v3", "AbundantCode v3", }; using (var conn = new SqlConnection(AbundantCode.GetConnectionString())) { conn.Open(); } Console.ReadLine(); } } }
Leave a Reply