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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 9, 2013, 6:46 AM EDT
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 Jul 9, 2013, 6:57 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 9, 2013, 7:10 AM EDT
Unfortunately, sizeof doesn't work with reference types such as string.
Posted Jul 9, 2013, 7:14 AM EDT
Posted Mar 18, 2014, 4:16 AM EDT
using System;
class Test
{
static void Main()
{
Console.WriteLine(sizeof(decimal));//16
Console.ReadKey();
}
}
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 4:20 AM EDT
Posted Mar 18, 2014, 4:49 AM EDT
Posted Apr 21, 2014, 11:34 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 21, 2014, 1:41 PM EDT
Posted Apr 22, 2014, 3:51 AM EDT