Properties and fields dude.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi to forum...

If i have this..

protected SqlConnection mycnx;

public SqlConnection MyCnx
{
get{return mycnx;}
set{mycnx=value;}
}

Main method
{
this.mycnx=new SqlConnection("Data..........")
}

the value of mycnx is stored in MyCnx automatically?

Thanks in advance
Julian
 
protected SqlConnection mycnx

public SqlConnection MyCn

get{return mycnx;
set{mycnx=value;


Main metho

this.mycnx=new SqlConnection("Data.........."


the value of mycnx is stored in MyCnx automatically

There is no value stored in MyCnx. MyCnx is just a method that sets the myCnx reference or gets the myCnx reference
If you changed myCnx then of course the results you get from MyCnx will be different. The property itself is nothing special, just an accessor
You could for example have it and it would function in exactly the same manner

public void GetMyCnx(

return myCnx

public void SetMyCnx(SqlConnection newConnection

myCnx = newConection
}
 
Julian said:
If i have this..

protected SqlConnection mycnx;

public SqlConnection MyCnx
{
get{return mycnx;}
set{mycnx=value;}
}

Main method
{
this.mycnx=new SqlConnection("Data..........")
}

the value of mycnx is stored in MyCnx automatically?

MyCnx doesn't really exist - it's just a way of accessing the data in
mycnx. Properties are really just another syntax for methods, really.
Think of it this way:

protected SqlConnection mycnx;

public SqlConnection get_MyCnx()
{
return mycnx;
}

public void set_MyCnx(SqlConnection value)
{
this.mycnx=value;
}

Thus setting mycnx doesn't "automatically store" anything else - but
when you call get_MyCnx you see the new value.
 
public class Mis

SqlConnection __MiscData

public SqlConnection MiscDat

set{__MiscData=value;
get{return __MiscData;

public static void Main(

Misc obj =new Misc()
obj.MiscData = new SqlConnection(@"server=local;integrated security=true;data source=pubs");
Console.WriteLine(obj.MiscData)
Console.WriteLine(obj.MiscData.State)



This will work and stores the sqlconnection object in the member. Hope you this is what you wan

Thank
Shyam.
 
Back
Top