|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
why ever use structs vrs. classes?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, Juan Dent, M.Sc. 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 Show quote "Juan Dent" <Juan_Dent@nospam.nospam> schreef in bericht news:8AE7EC98-A85A-4268-9AA1-8A4962AF8FF8@microsoft.com... > 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, > > Juan Dent, M.Sc. Juan Dent wrote:
> Hi, I first learned C in 1988 before there was such a thing as classes (at> > 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? 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. Juan Dent wrote:
> Hi, If local variable, struct is not a subject to garbage collection.> > 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? This could be beneficial if you have many of them, e.g., like points and sizes during frequent calculations in paint events. 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.) |
|||||||||||||||||||||||