Click here to Skip to main content
16,016,489 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I want to know how many byte contains the value 0x80000L888 which is of type System.Single ?
Posted
Updated 29-Jul-11 3:59am
v2

You call single a structure? It is a structure in fact? Yes and no. All primitive types comes in their original form or in a boxed form. Only a boxed form is a structure. These two forms have different size (boxed is larger; also, it's a class).

Read about boxing: http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[^].

—SA
 
Share this answer
 
To know size of a value type you could probably use below,

C#
static void Main(string[] args)
{
    Console.WriteLine("{0}",sizeof(Single));
}


:)
 
Share this answer
 
Comments
Olivier Levrey 29-Jul-11 10:19am    
Good advice. My 5.
Mohammad A Rahman 29-Jul-11 10:33am    
Thank you :)
Sergey Alexandrovich Kryukov 2-Aug-11 3:41am    
True, but the title of the question implies boxed form (or rather OP needs explanation of it).
So, please see my solution.
--SA
A Single is always 4 bytes, regardless of the number you store in it.

However, you can't assign 0x80000L888 to it - 'L' is not a valid hex digit!
 
Share this answer
 
Comments
Olivier Levrey 29-Jul-11 10:19am    
Everything is said! My 5.
Sergey Alexandrovich Kryukov 2-Aug-11 3:39am    
Not quite everything. Look at the title of the question. This is about boxing.
Please see my solution as well.
--SA
Manas Bhardwaj 29-Jul-11 11:17am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900