bpayne111 Posted March 5, 2003 Posted March 5, 2003 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 Quote i'm not lazy i'm just resting before i get tired.
AndreRyan Posted March 5, 2003 Posted March 5, 2003 Either will probably work becuase object can be turned into MyClassName and MyClassName can be turned into object Quote .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?
bpayne111 Posted March 5, 2003 Author Posted March 5, 2003 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) Quote i'm not lazy i'm just resting before i get tired.
AndreRyan Posted March 5, 2003 Posted March 5, 2003 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 Quote .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?
*Gurus* divil Posted March 5, 2003 *Gurus* Posted March 5, 2003 Why would you inherit from ArrayList? If you need to make a collection of your own type, you should inherit from CollectionBase and provide your own accessor and add, remove functions etc. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 5, 2003 Author Posted March 5, 2003 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? Quote i'm not lazy i'm just resting before i get tired.
*Experts* Nerseus Posted March 5, 2003 *Experts* Posted March 5, 2003 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 Quote "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
bpayne111 Posted March 5, 2003 Author Posted March 5, 2003 isee what i need to do now but does that mean i define what a shallow copy is in this method myself? thanks Quote i'm not lazy i'm just resting before i get tired.
TechnoTone Posted March 5, 2003 Posted March 5, 2003 Aha, once again i've made a foolish mistake... Making mistakes isn't foolish... not learning from them is. ;) Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
*Gurus* divil Posted March 5, 2003 *Gurus* Posted March 5, 2003 Could it be that a value type would be more suited for your needs, in this instance? That way when you pass them only a copy is passed. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted March 5, 2003 *Experts* Posted March 5, 2003 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 Quote "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
bpayne111 Posted March 5, 2003 Author Posted March 5, 2003 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 Quote i'm not lazy i'm just resting before i get tired.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.