Click here to Skip to main content
15,900,258 members
Home / Discussions / C#
   

C#

 
QuestionClass Objects and Equals Operator Pin
budidharma1-Nov-05 3:59
budidharma1-Nov-05 3:59 
AnswerRe: Class Objects and Equals Operator Pin
Judah Gabriel Himango1-Nov-05 4:56
sponsorJudah Gabriel Himango1-Nov-05 4:56 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 5:17
budidharma1-Nov-05 5:17 
AnswerRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 4:59
[Marc]1-Nov-05 4:59 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 5:21
budidharma1-Nov-05 5:21 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 6:27
[Marc]1-Nov-05 6:27 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 7:23
budidharma1-Nov-05 7:23 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 9:28
[Marc]1-Nov-05 9:28 
I couldn't find a tutorial either, it's a shame Poke tongue | ;-P
Anyway, here's round about i would do it. Of course, you can do it some other way if you want.
// Make class implement IClonable
public class MyDef : ICloneable
{
 private int someInt;
 private string someString;

 // Default constructor
 public MyDef()
 {
 }

 // Protected constructor, for cloning/copying
 protected MyDef(MyDef original)
 {
   // Copy all the fields from original
   this.someInt = original.someInt;
   this.someString = original.someString;
 }

 // IClonable implementation
 // Advantage: you've implemented IClonable, thats ususally a good thing if you want your class to be copyable
 // Disadvantage: You have to manually cast the returned object to a MyDef
 public object Clone()
 {
   return new MyDef(this);
 }

 // If you want, you can do this (like your copy(obj1, obj2) idea)
 // Advantage: -It's static, so you can just do MyDef.Copy(...)
 //            -The returned value is already of type MyDef, no need to typecast  
 // Disadvantage: It's not the way it's 'supposed' to go
 public static MyDef Copy(MyDef original)
 {
   return new MyDef(original);
 }
}
If you want, you can use both the Clone and the Copy way, it's just a matter of taste Smile | :) .

Pompiedompiedom... Wink | ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick

GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 14:36
budidharma1-Nov-05 14:36 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 17:33
[Marc]1-Nov-05 17:33 
GeneralRe: Class Objects and Equals Operator Pin
budidharma2-Nov-05 2:00
budidharma2-Nov-05 2:00 
GeneralRe: Class Objects and Equals Operator Pin
budidharma2-Nov-05 2:04
budidharma2-Nov-05 2:04 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]3-Nov-05 0:56
[Marc]3-Nov-05 0:56 
GeneralRe: Class Objects and Equals Operator Pin
Febret1-Nov-05 6:39
Febret1-Nov-05 6:39 
AnswerRe: Class Objects and Equals Operator Pin
S. Senthil Kumar1-Nov-05 19:15
S. Senthil Kumar1-Nov-05 19:15 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]3-Nov-05 1:24
[Marc]3-Nov-05 1:24 
QuestionGetting Enum Type from Value Pin
budidharma1-Nov-05 3:10
budidharma1-Nov-05 3:10 
AnswerRe: Getting Enum Type from Value Pin
Libor Tinka1-Nov-05 3:20
Libor Tinka1-Nov-05 3:20 
AnswerRe: Getting Enum Type from Value Pin
S. Senthil Kumar1-Nov-05 3:22
S. Senthil Kumar1-Nov-05 3:22 
GeneralRe: Getting Enum Type from Value Pin
budidharma1-Nov-05 4:30
budidharma1-Nov-05 4:30 
Questionhow to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
lokeshkumble1-Nov-05 2:52
lokeshkumble1-Nov-05 2:52 
AnswerRe: how to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
J4amieC1-Nov-05 4:11
J4amieC1-Nov-05 4:11 
GeneralRe: how to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
lokeshkumble1-Nov-05 21:14
lokeshkumble1-Nov-05 21:14 
QuestionSystem.Data.Odbc Pin
zaboboa1-Nov-05 2:41
zaboboa1-Nov-05 2:41 
AnswerRe: System.Data.Odbc Pin
S. Senthil Kumar1-Nov-05 3:28
S. Senthil Kumar1-Nov-05 3:28 

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.