Posts

Showing posts from September 29, 2018

How to determine the size of var?

Image
Clash Royale CLAN TAG #URR8PPP up vote 7 down vote favorite 1 I Have a variable declared as follows: var a = 99494; Then I used the following to determine the size of the variable in bytes: Marshal.SizeOf(a) Does it get the actual size of memory occupied by this value ? c# share | improve this question edited Sep 11 at 7:59 Patrick Hofman 122k 18 160 210 asked Sep 11 at 7:55 sajis997 283 1 8 5 var is just "I don't want to write the type of this variable. Compiler, please do that work and pretend I wrote the type instead". – Damien_The_Unbeliever Sep 11 at 7:58 1 The actual code will be compiled as though you wrote int a = 99494; since 99494 is of type int . – Lasse Vågsæther Karlsen Sep 11 at 8:02 1 int size = sizeof(a); since 99494 is of type int ( Int32 ) it takes 32 bits = 4 bytes – Dmitry Bychenko Sep 11 at 8:11 add a comment  |  up vote