PC Review


Reply
Thread Tools Rate Thread

Differences between struct and class

 
 
puzzlecracker
Guest
Posts: n/a
 
      8th Oct 2008
what are the most usable, prominent, and must-to-know ones?
 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      8th Oct 2008
puzzlecracker wrote:
> what are the most usable, prominent, and must-to-know ones?


From a previous post you seem to be thinking of the C# type system in
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.
 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      8th Oct 2008
On Oct 8, 7:04*am, puzzlecracker <ironsel2...@gmail.com> wrote:
> what are the most usable, prominent, and must-to-know ones?


This is a FAQ. Here's a Google Groups link to the last (as far as I
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?":
http://groups.google.com/group/micro...45559a938e1af0
 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      8th Oct 2008
puzzlecracker wrote:
> what are the most usable, prominent, and must-to-know ones?


The most fundamental is that a class is a reference type and a struct is
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
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
struct or class Jure Bogataj Microsoft C# .NET 9 28th Aug 2007 09:25 PM
Struct vs Class JohnGoogle@hotmail.co.uk Microsoft C# .NET 37 3rd Nov 2006 02:10 AM
struct or class? Lloyd Dupont Microsoft C# .NET 9 26th Jun 2006 06:29 AM
C# - Struct in a class.. can not access properties of the struct =?Utf-8?B?U0FDSElO?= Microsoft Dot NET 2 28th Jan 2004 10:17 PM
Re: Class vs. Struct Jon Skeet Microsoft C# .NET 0 18th Jul 2003 07:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:58 PM.