Bala,
class Class_Name
{
private string _connectionString; // this is a member variable...
private SqlConnection _con;
public Global(string connString);
{
_con = new SqlConnection(connString); // member variable
created on the heap and would be available for use outside the scope of this
method.
SqlDataAdapter _da = new SqlDataAdapter(); // this is a local
variable... not available and gc'd after the method call
}
}
as for whether you should define it connection string as a member variable
to the class... well if you dont need to use connection string anywhere
else... then why make an extra call to assign it to a local variable or a
data memeber.. .rather read it from the passed value and instantiate your
object...
but if you feel the need to access the connection string assigned from say
lot many method calls... assign it to a data member so that you dont have to
write calls to repeatedly pass it... instead since the passed value is
stored in data member it can be accessed....
hope this helps,
hd
"Balaji Kannan" <ba******@msdc.hcltech.com> wrote in message
news:02****************************@phx.gbl...
Hi,
In dot net during component development i have used some
member variables in the class file. Inside the class i
have used the member declaration and the instant handling
in the following way.
In the constructor i have created the connection instant
in the following way
public Global(string connString)
{
//member variable
private Sqlconnection m_connDB;
.......
.......
m_connDB = new SqlConnection(connString);
.....
.....
}
In otherway we can do the member declaration and the
object creation in the same place. That is
public Global(string connString)
{
//member variable
private Sqlconnection m_connDB = new SqlConnection
(connString);
.......
......
.....
.....
}
Among the above which one is best as for the performance
is concerned. Which one is more advisable? Can anyone
guide me..
Advance thanks and regards