Hi Allan,
You are passing the parameter as value that's why it's not changed back in
the code, you could either pass it as ref or use instead the return value
for doing this:
private void Page_Load(object sender, System.EventArgs e)
{
Label l;
l = new Label();
l.Text="Original label";
l = CreateSomething();
Response.Write(l.Text);
}
private Label CreateSomething()
{
l = new Label();
l.Text="New Label";
return l;
}
What are you trying to do anyway?
Remember that the old l will only cease of exist if there are not any other
variable referencing it. ( as in the example above) .
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Allan Lembo" <Al********@mailinator.com> wrote in message
news:d4**************************@posting.google.c om...
Hi Folks
If I create a new instance of an object within a method how can I pass
it back by reference?
For example, the following code, in the context of an ASP.NET page,
returns "Original Label". Why not "New Label"? I realise I could give
CreateSomething a return type of Label and return it that way but in
my case I have more than one parameter that could need reinstancing.
Thanks, Al.
private void Page_Load(object sender, System.EventArgs e)
{
Label l;
l = new Label();
l.Text="Original label";
CreateSomething(l);
Response.Write(l.Text);
}
private void CreateSomething(Label l)
{
l = new Label();
l.Text="New Label";
}