Click here to Skip to main content
15,902,299 members
Home / Discussions / C#
   

C#

 
GeneralRe: Debugging class library (DLL) Pin
raed10-Oct-05 2:44
raed10-Oct-05 2:44 
QuestionPage.IsPostBack Pin
Brendan Vogt9-Oct-05 21:47
Brendan Vogt9-Oct-05 21:47 
AnswerRe: Page.IsPostBack Pin
David Stone10-Oct-05 5:43
sitebuilderDavid Stone10-Oct-05 5:43 
QuestionHelp required on remote objects in C# Pin
kschakravarthy9-Oct-05 20:41
kschakravarthy9-Oct-05 20:41 
AnswerRe: Help required on remote objects in C# Pin
S. Senthil Kumar10-Oct-05 2:19
S. Senthil Kumar10-Oct-05 2:19 
GeneralRe: Help required on remote objects in C# Pin
kschakravarthy10-Oct-05 20:56
kschakravarthy10-Oct-05 20:56 
QuestionProcess Large File Results Server Application Unavailable Pin
Member 14325389-Oct-05 20:00
Member 14325389-Oct-05 20:00 
AnswerRe: Process Large File Results Server Application Unavailable Pin
Guffa10-Oct-05 0:55
Guffa10-Oct-05 0:55 
QuestionRTF (RichText) draw using GDI+ like VISIO 2003 style. Richtext able to rotate and translate. Pin
thewizardcode9-Oct-05 18:31
thewizardcode9-Oct-05 18:31 
QuestionRS 232 Programming Pin
mipooo9-Oct-05 18:17
mipooo9-Oct-05 18:17 
QuestionSaving Excel workbook in SQL server using c# Pin
Member 22989639-Oct-05 18:09
Member 22989639-Oct-05 18:09 
QuestionHow do i make controls that are transparent, but still show the form behind them? Pin
Red_Wizard_Shot_The_Food9-Oct-05 15:46
Red_Wizard_Shot_The_Food9-Oct-05 15:46 
AnswerRe: How do i make controls that are transparent, but still show the form behind them? Pin
Red_Wizard_Shot_The_Food9-Oct-05 18:07
Red_Wizard_Shot_The_Food9-Oct-05 18:07 
GeneralRe: How do i make controls that are transparent, but still show the form behind them? Pin
XRaheemX10-Oct-05 10:08
XRaheemX10-Oct-05 10:08 
GeneralRe: How do i make controls that are transparent, but still show the form behind them? Pin
Red_Wizard_Shot_The_Food10-Oct-05 11:17
Red_Wizard_Shot_The_Food10-Oct-05 11:17 
QuestionC# http post Pin
aerosmith2k19-Oct-05 14:56
aerosmith2k19-Oct-05 14:56 
QuestionCOM objects written C# then use in MS Access Application Pin
ehuelgas9-Oct-05 14:51
ehuelgas9-Oct-05 14:51 
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

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.