operator overld. struct vs. class

J

Jesper

Hi,

Are there any serious drawbacks using a class instead of
struct to implementing your own type.

I a textbook of mine on C# the author recommend operator
overloading on value types only. Apparantly based on some
argument that e.g. the ++ operator is more complex to
implement. Can this really be his only reason for this
argument?

Moreover, in a struct, the same aurthor defines the
following

struct Hour
{
.....
.....
private int value;
}

Does he obtain something special using the value keyword
as a field of the struct?

Best regards Jesper
 
F

Frank Oquendo

Jesper said:
I a textbook of mine on C# the author recommend operator
overloading on value types only. Apparantly based on some
argument that e.g. the ++ operator is more complex to
implement. Can this really be his only reason for this
argument?

Overloading operators may be a bit more detailed with reference types
but I wouldn't say it's more complex. You just have to make sure your
overload has the type of semantics you'd expect from it.
Does he obtain something special using the value keyword
as a field of the struct?

Nope. C# will let you use this keyword as just another variable name.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top