another topic on this question as i'm tired of reading countless topics to find the answer to my questions :)
Suppose we have the following class:
public class MyClass
{
private const string conString = "connection string";
private int Operation()
{
int count = 0;
using(var con = SqlConnection(conString))
{
string select_cmd = "SELECT * FROM TABLE";
using(var cmd = new SqlCommand(select_cmd, con))
{
using(var reader = cmd.ExecuteReader())
{
while(reader != null && reader.Read())
count++;
}
}
}
return count;
}
}
Since the database connection is created inside the using statement, the con.close () and finally con.dispose () methods will be called, is it necessary to implement IDisposable for MyClass? Will MyClass collect garbage when it goes beyond?
EDIT:
Thanks for your answers, that’s what I thought, but I had to make it clear. One more question.
(), , , SqlConnection, IDisposable "" ( )?
, MyClass .