Variable = Variable?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I'm not really new to dotnet but am getting stumped by what I think is
something easy.
Any insights as to what i'm doing wrong?

Thanks in advanced (see below)

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = clone;
}
}
 
You are setting the variable 'group' to the value of the variable named
'clone'. Close is not being set to anything in the code you have here, so
we can assume it is null. So you are setting 'group' to null.

This does nothing to your collection. Or to the Group object that 'group'
was set to before you set it to null.

What are you trying to do anyway? Why are you cloning things?
 
Sorry did have all my code in there... The clone is really irrelevant and
doesn;t need to be used here, i was testing it though. Same prob exists
when not using clone as well.
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone;
}
}

Ron
Marina said:
You are setting the variable 'group' to the value of the variable named
'clone'. Close is not being set to anything in the code you have here, so
we can assume it is null. So you are setting 'group' to null.

This does nothing to your collection. Or to the Group object that 'group'
was set to before you set it to null.

What are you trying to do anyway? Why are you cloning things?

Ron said:
I'm not really new to dotnet but am getting stumped by what I think is
something easy.
Any insights as to what i'm doing wrong?

Thanks in advanced (see below)

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = clone;
}
}
 
messed this one up as well should be...

Group clone = (Group) e.Group.Clone();
group = clone;

Ron said:
Sorry did have all my code in there... The clone is really irrelevant and
doesn;t need to be used here, i was testing it though. Same prob exists
when not using clone as well.
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone;
}
}

Ron
Marina said:
You are setting the variable 'group' to the value of the variable named
'clone'. Close is not being set to anything in the code you have here,
so we can assume it is null. So you are setting 'group' to null.

This does nothing to your collection. Or to the Group object that 'group'
was set to before you set it to null.

What are you trying to do anyway? Why are you cloning things?

Ron said:
I'm not really new to dotnet but am getting stumped by what I think is
something easy.
Any insights as to what i'm doing wrong?

Thanks in advanced (see below)

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = clone;
}
}
 
You are using a clone in this example also.
Assuming that the Name property is a string, how can you set it to an
instance of a Group? I can't see how that would compile.

In any case, I already explained the issue.

Ron said:
messed this one up as well should be...

Group clone = (Group) e.Group.Clone();
group = clone;

Ron said:
Sorry did have all my code in there... The clone is really irrelevant
and doesn;t need to be used here, i was testing it though. Same prob
exists when not using clone as well.
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone;
}
}

Ron
Marina said:
You are setting the variable 'group' to the value of the variable named
'clone'. Close is not being set to anything in the code you have here,
so we can assume it is null. So you are setting 'group' to null.

This does nothing to your collection. Or to the Group object that
'group' was set to before you set it to null.

What are you trying to do anyway? Why are you cloning things?

I'm not really new to dotnet but am getting stumped by what I think is
something easy.
Any insights as to what i'm doing wrong?

Thanks in advanced (see below)

-------------------
This works...
-----------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
Group clone = (Group) e.Group.Clone();
group.Name = clone.Name;
}
}

-------------------------------------
This Doesn't
--------------------------------------
e.Group.Name = "Changed Name";

GroupCollection groups = Application [ "EHIMOnline_Groups" ] as
GroupCollection;

if ( groups != null )
{
Group group = groups.Find ( e.Group.GroupID );

if ( group != null )
{
group = clone;
}
}
 
variables are object pointers.

Group group1 = new Group(); // create an object
Group clone = group1; // group and clone point to same object
clone.Name = "foo"; // update property in the object
clone = new Group(); // now clone points to a new object
clone.Name = "foo2"; // update prop in new object

string name = group.Name; // will = foo
string name 2 = clone.Name // will = foo2;


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top