Data Types
This book didn't tell about how many bytes are string, char and bool. I wish to know why. I attach the book page.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 9, 2013, 10:46 AM
bool 1 byte
char 2 bytes
string 16 bytes plus 2 bytes per character plus 2 bytes for the final null character.
In the rare cases of 'surrogate pairs' (characters which can't be represented within the normal unicode range), the char type requires 4 bytes rather than 2 bytes.
64-bit versions of Windows require 8 bytes more storage for strings than the above formula gives.
The null character at the end of strings isn't actually part of the string but is needed for interop with unmanaged code.
Posted Apr 22, 2014, 7:51 AM
VulpesPosted Apr 21, 2014, 5:41 PM
Posted Apr 21, 2014, 3:34 PM
Posted Mar 18, 2014, 8:49 AM
VulpesPosted Mar 18, 2014, 8:20 AM
Posted Mar 18, 2014, 8:16 AM
using System;
class Test
{
static void Main()
{
Console.WriteLine(sizeof(decimal));//16
Console.ReadKey();
}
}
Posted Jul 9, 2013, 11:14 AM
VulpesPosted Jul 9, 2013, 11:10 AM
Unfortunately, sizeof doesn't work with reference types such as string.
Posted Jul 9, 2013, 10:57 AM