| re: Which is advisable for object creation?
since you define the members as being private explicitly i would presume
that they are data members belonging to a class.
for datamembers it is better to declare a reference and then use constructor
to create an instance for the ref.
Performance., not a big deal. Cause the compilers their own optimisations
your code so what you write may not be output.
Think the second one internally maps to the first one.... but i would say
write two and compare the msil.
Hope this helps
HD
"Balaji kannan" <balajikn@msdc.hcltech.com> wrote in message
news:032201c3cb89$dc6a7bf0$a501280a@phx.gbl...[color=blue]
> hi,
> My actual question is, which of the following coding is
> best for performance gain.
>
> 1. private Sqlconnection m_connDB;
> m_connDB = new SqlConnection(connString);
>
> 2. private Sqlconnection m_connDB = new SqlConnection
> (connString);
>
> in the first case, i have created reference variable then
> assigning object to that variable.
>
> In the second case, while creating variable itself
> assigning values.
>
> Which one is best?? please let me know.
>
> Thanks,
> Bala
>[color=green]
> >-----Original Message-----
> >Bala,
> >
> >class Class_Name
> >{
> > private string _connectionString; // this is a[/color]
> member variable...[color=green]
> > private SqlConnection _con;
> > public Global(string connString);
> > {
> > _con = new SqlConnection[/color]
> (connString); // member variable[color=green]
> >created on the heap and would be available for use[/color]
> outside the scope of this[color=green]
> >method.
> > SqlDataAdapter _da = new SqlDataAdapter(); //[/color]
> this is a local[color=green]
> >variable... not available and gc'd after the method call
> > }
> >}
> >
> >as for whether you should define it connection string as[/color]
> a member variable[color=green]
> >to the class... well if you dont need to use connection[/color]
> string anywhere[color=green]
> >else... then why make an extra call to assign it to a[/color]
> local variable or a[color=green]
> >data memeber.. .rather read it from the passed value and[/color]
> instantiate your[color=green]
> >object...
> >but if you feel the need to access the connection string[/color]
> assigned from say[color=green]
> >lot many method calls... assign it to a data member so[/color]
> that you dont have to[color=green]
> >write calls to repeatedly pass it... instead since the[/color]
> passed value is[color=green]
> >stored in data member it can be accessed....
> >
> >hope this helps,
> >
> >hd
> >
> >"Balaji Kannan" <balajikn@msdc.hcltech.com> wrote in[/color]
> message[color=green]
> >news:02be01c3cb7b$18a02430$a401280a@phx.gbl...[color=darkred]
> >> 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[/color][/color]
> handling[color=green][color=darkred]
> >> 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[/color]
> >
> >
> >.
> >[/color][/color] |