Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2007, 05:55 PM
Registered User
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default SizeOf Structs

Hi,

Somebody please help me to understand something

i have this struct for example :

    struct Test
    {
        public long l1;
        public char c2;

    }
    class Program
    {
        static unsafe void Main(string[] args)
        {
            Console.WriteLine(sizeof(Test));
            Console.ReadKey();
        }
    }
long (8) + char(2)(that will overhead more 2) = 12 bytes
why sizeof(Test) gives 16 ?
thanks !

 
Old February 21st, 2007, 06:24 PM
Registered User
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

    struct Test
    {
        public decimal d1;
        public byte c2;

    }

this example gives 20 !
Why ?

Thanks !






Similar Threads
Thread Thread Starter Forum Replies Last Post
Enums VS Structs MoDulus Intro Programming 4 January 19th, 2012 10:42 AM
arrays of structs seymour_glass C# 2 April 2nd, 2007 08:14 PM
declaring structs scoobie C++ Programming 3 April 6th, 2006 12:44 AM
sizeof Integer in infopath vikram_vikram Infopath 0 November 30th, 2005 08:42 AM
sizeof joeben C# 1 April 2nd, 2005 08:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.