Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When overriding the clone method of an arraylist should i let it Return Object as default or change this to MyClassName?

i have a feeling i'm supposed to leave it as object but i don't understand why...

 

any thoughts, ideas and crude remarks appreciated

i'm not lazy i'm just resting before i get tired.
Posted
Either will probably work becuase object can be turned into MyClassName and MyClassName can be turned into object
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

yes, but i feel there is some generally accepted principle i am missing in this instance

ie. sender is always object in an event, this is ovious but why not make it the same type as the calling object? (in this case could delegates be involved... i'll save those questions for another day)

i'm not lazy i'm just resting before i get tired.
Posted
Becuase events can be triggered by different classes with no real connection to each other(ie. MyEvent(Sender as Object,e as ...), the sender could be a windows control or a class which are not neccessarily related(derived from the same base)). You'll probably want to return it as an Object becuase if its a clone, you'll want it programmer to be able to attach the clone as a derived object
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

Aha, once again i've made a foolish mistake...

This brings me to another question.. suprise suprise

 

Public Overrides Function Clone() as Object

 

Return Me

 

End Function

 

Would this return a deep copy? How do i return a shallow copy?

i'm not lazy i'm just resting before i get tired.
  • *Experts*
Posted

You need to create a new instance of your class type (whatever it is), and set all properties of the new class to the current instance (Me). Return the new instance in the Clone function.

 

If all of your private fields are value types, you can use Me.Clone() instead. If you have ANY fields that are objects, you'll have to do it manually.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

isee what i need to do now but does that mean i define what a shallow copy is in this method myself?

 

thanks

i'm not lazy i'm just resting before i get tired.
Posted
Aha, once again i've made a foolish mistake...

Making mistakes isn't foolish... not learning from them is. ;)

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

  • *Experts*
Posted

To be clearer (in case you didn't know what divil meant), could you make your class a struct instead? Then using asignment would make an actual copy instead of just assigning the pointer to the same instance. Also, passing a struct ByRef would pass a copy of the object rather than just a reference.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I see what you mean... I think it could be possible

So if i passed a structure instead of my class itself the properties would not be altered?

I need to keep it as an object because i need to inherit from it for the UI's class

i also have trouble understanding the difference in types and objects. i've read a little on it but i still feel kinda confused about it.

 

you guys are great thanks

i'm not lazy i'm just resting before i get tired.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...