what are the most usable, prominent, and must-to-know ones?
Differences between struct and class
Collapse
This topic is closed.
X
X
-
puzzlecrackerTags: None -
John
Re: Differences between struct and class
puzzlecracker wrote:From a previous post you seem to be thinking of the C# type system inwhat are the most usable, prominent, and must-to-know ones?
terms of C++. You cannot do this, often the primary differences between
languages are their types systems. For instance C uses a "tag" system,
C++ uses a "type" system where everything is a "type" i.e. a class (well
except fundamental types, anyways, we're not talking C++).
In C# there is are two fundamental types Value types (structs) and
Reference types (classes). This effects, primarily their equality and
assignment semantics, and thus the way they are passed as parameters to
methods. These semantics permeate everything, it is not like C++ where
parameters are passed by value by default but can be pass by reference
using the reference operator (&). There is no such construct on C#,
value types are value types and reference types are reference types,
forever. Well not quite, you can "box" a Value type into a Reference
type, something that should generally be avoided.
Comment
-
Pavel Minaev
Re: Differences between struct and class
On Oct 8, 7:04 am, puzzlecracker <ironsel2...@gm ail.comwrote:This is a FAQ. Here's a Google Groups link to the last (as far as Iwhat are the most usable, prominent, and must-to-know ones?
remember) discussion on the topic - it has my long post, and I do not
want to retype it :)
"Why are some types implemented as struct?":
Comment
-
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Re: Differences between struct and class
puzzlecracker wrote:The most fundamental is that a class is a reference type and a struct iswhat are the most usable, prominent, and must-to-know ones?
a value type.
To work well, a struct should be small and immutable. The members of a
struct are generally value types (with a possible exception for strings,
as they are also immutable).
If you don't have any special reason to use a struct, stick to creating
classes.
--
Göran Andersson
_____
Comment
Comment