|
-
September 28th, 2010, 03:14 AM
#1
Automatic definition of Equals etc?
Hi,
I'm in the process of learning C#. Coming from C++, I'm used to getting some methods for free from the compiler, most notably an equality operator (that tests equality of all fields) and a copy constructor.
In C#, it seems I have to write these methods myself, except if I use structs instead of classes, where equality and copying are automatically defined. However, since everyone seems to recommend against using structs in most cases, I wonder if it is possible to get anything similar with classes. That is, can I in any way instruct the compiler to make a default Equals method and copy constructor for my class?
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|