does the "this" operator create implicite objects?
hi friends,
cosnider following class:
public class a
{
int i;
decimal j;
b myb;
public a()
{
i = 15; //---------> line 1
this.j = 23.50; //----------->line 2
myb = new b(); //-------------->line 3
myb.count = 2; //-------------->line 4
}
}
public class b
{
int count;
}
in there have highlighted several ways assign values members.
in line 1, memeber value assign happens through calling member directly
in line2, memeber value assign happens through calling member through current object of class. class creates implicite object first, assign value member through object
in line 4, member value assign happens through calling member through explictely create object of class b
what need know (actually double checking), in line 2, this operator creates internal object of current class?
in line 1, statement assigns member value, without creating object implicitely (internally)?
thanks
in example above, "this->j = 23.5" sets value of j in current instance of class. same "j = 23.5". this-> operator not used in way, because it's redundant, although may used emphasis make clear "j" in case class's property , not local loop counter or whatever.
there few special cases this-> needed, such when class wants pass reference class.
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment