C#: What takes up more memory? A string or bytes?
Let’s say I have a line that reads “My Text”, in which form would that line use up more memory, as a byte or a string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The byte array. This will store your text as ASCII (1 byte per character) characters, whereas a .NET string uses Unicode which are larger. However remember that .NET strings are probably more useful and in a large application the difference probably won’t make a huge difference.
(note also that if you just use ASCII characters in your .NET string then the characters will still only be 1 byte each)