Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
QuestionGood Intersection Function Pin
Baatezu9-Oct-05 13:31
Baatezu9-Oct-05 13:31 
AnswerRe: Good Intersection Function Pin
Super Lloyd9-Oct-05 14:23
Super Lloyd9-Oct-05 14:23 
QuestionHow can i...?Please help me please !!!! Pin
snouto9-Oct-05 13:27
snouto9-Oct-05 13:27 
AnswerRe: How can i...?Please help me please !!!! Pin
Dave Kreskowiak9-Oct-05 14:50
mveDave Kreskowiak9-Oct-05 14:50 
GeneralRe: How can i...?Please help me please !!!! Pin
snouto10-Oct-05 0:01
snouto10-Oct-05 0:01 
GeneralRe: How can i...?Please help me please !!!! Pin
Dave Kreskowiak10-Oct-05 4:33
mveDave Kreskowiak10-Oct-05 4:33 
AnswerRe: How can i...?Please help me please !!!! Pin
Brendan Vogt9-Oct-05 23:06
Brendan Vogt9-Oct-05 23:06 
QuestionUsage of ICloneable Pin
Robert Rohde9-Oct-05 9:55
Robert Rohde9-Oct-05 9:55 
Hi everyone,

this is not really a programming question, but as I made some thoughts about cloning my objects I had an idea and just want to hear some comments on it.

Normally when a class should be cloneable it implements ICloneable like this:
public class TestClass : ICloneable {
   public object Clone() {
      //Do something
   }
}


The nasty thing about this is that everybody who calls Clone will have to do a cast afterwards (assuming the caller wants to do something with the result where object doesn't help).

Do avoid this one could just forget ICloneable and make a typed Clone method:
public class TestClass {
   public TestClass Clone() {
      //Do something
   }
}


Sadly this isn't an option for me because at some places in my code I have an ArrayList which holds objects of several different classes which I all have to clone.

So I came to the idea to instead combine the two methods and do the following:
public class TestClass : ICloneable {
   object ICloneable.Clone() {
      return this.Clone();
   }

   public TestClass Clone() {
      //Do something
   }
}


So now when I use a variable of type TestClass the Clone method will return TestClass, but I can use it also as an ICloneable where I get an object (Truly also having the type TestClass but unknown to the caller).

So what are your thoughts about it? I think this casting problem when using Clone is relatively widespread, but why is everybody using (I refer to the framework and some 3rd party components) just the naiv method?


PS: Why is the result of ICloneable.Clone an object and not ICloneable? I thought the intention of this interface was that the result should be some kind of deep copy of the object and should always have the same type... Confused | :confused:

-- modified at 15:56 Sunday 9th October, 2005
AnswerRe: Usage of ICloneable Pin
S. Senthil Kumar9-Oct-05 19:09
S. Senthil Kumar9-Oct-05 19:09 
QuestionCreate new dialog from Pin
Gedrain9-Oct-05 9:27
Gedrain9-Oct-05 9:27 
AnswerRe: Create new dialog from Pin
Dave Kreskowiak9-Oct-05 14:47
mveDave Kreskowiak9-Oct-05 14:47 
GeneralRe: Create new dialog from Pin
Gedrain9-Oct-05 14:49
Gedrain9-Oct-05 14:49 
GeneralRe: Create new dialog from Pin
Dave Kreskowiak10-Oct-05 4:26
mveDave Kreskowiak10-Oct-05 4:26 
AnswerRe: Create new dialog from Pin
S. Senthil Kumar9-Oct-05 19:12
S. Senthil Kumar9-Oct-05 19:12 
Questionfactorial program Pin
johnjsm9-Oct-05 8:34
johnjsm9-Oct-05 8:34 
AnswerRe: factorial program Pin
Robert Rohde9-Oct-05 8:47
Robert Rohde9-Oct-05 8:47 
AnswerRe: factorial program Pin
Anonymous9-Oct-05 20:52
Anonymous9-Oct-05 20:52 
QuestionRunning a batch file in a process from C# code in Windows98 at startup Pin
Bilal Farooq9-Oct-05 7:29
Bilal Farooq9-Oct-05 7:29 
AnswerRe: Running a batch file in a process from C# code in Windows98 at startup Pin
Dave Kreskowiak9-Oct-05 14:43
mveDave Kreskowiak9-Oct-05 14:43 
QuestionCan't get Big Arrow on small Line Pin
Anonymous9-Oct-05 7:01
Anonymous9-Oct-05 7:01 
AnswerRe: Can't get Big Arrow on small Line Pin
Robert Rohde9-Oct-05 8:58
Robert Rohde9-Oct-05 8:58 
GeneralRe: Can't get Big Arrow on small Line Pin
Anonymous9-Oct-05 9:33
Anonymous9-Oct-05 9:33 
QuestionApplication File Path Pin
Golden Dragon9-Oct-05 5:08
Golden Dragon9-Oct-05 5:08 
AnswerRe: Application File Path Pin
Guffa9-Oct-05 5:20
Guffa9-Oct-05 5:20 
AnswerRe: Application File Path Pin
Anoop Ananthan10-Oct-05 2:26
professionalAnoop Ananthan10-Oct-05 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.