Groups | Blog | Home
all groups > dotnet ado.net > august 2006 >

dotnet ado.net : why ever use structs vrs. classes?


Juan Dent
8/30/2006 10:58:02 AM
Hi,

I have a hard time recalling what was the basic rationales for using structs
instead of classes in a C# program. Could anyone point out the reasons?

--
Thanks in advance,

zacks NO[at]SPAM construction-imaging.com
8/30/2006 11:52:30 AM

[quoted text, click to view]

I first learned C in 1988 before there was such a thing as classes (at
least I had never heard of them at that time), and structs were all
there was available for grouping data together. I think that now, there
is little reason to use structs instead of classes and structs are
merely available for backwards compatability of some kind.
Sericinus hunter
8/30/2006 3:26:31 PM
[quoted text, click to view]

If local variable, struct is not a subject to garbage collection.
This could be beneficial if you have many of them, e.g., like
Cor Ligthert [MVP]
8/30/2006 8:06:11 PM
Juan,

That theory "was".

However I think that the discussion is done; in my idea were the
conclussions that the benefits are far below the benefits of using objects.

(Or it should be for API calls etc, but those are as well not clever
thinking about newer OS systems)

Cor

"Juan Dent" <Juan_Dent@nospam.nospam> schreef in bericht
news:8AE7EC98-A85A-4268-9AA1-8A4962AF8FF8@microsoft.com...
[quoted text, click to view]

v-kevy NO[at]SPAM online.microsoft.com
8/31/2006 1:09:01 AM
Hi Juan,

A struct type is a value type that can contain constructors, constants,
fields, methods, properties, indexers, operators, events, and nested types.
While class is a reference type, whose instances are created on managed
heap.

The struct type is suitable for representing lightweight objects such as
Point, Rectangle, and Color. Although it is possible to represent a point
as a class, a struct is more efficient in some scenarios. For example, if
you declare an array of 1000 Point objects, you will allocate additional
memory for referencing each object. In this case, the struct is less
expensive.

You will find more information from the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vcrefstructtypes.asp

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
AddThis Social Bookmark Button