C#中:什么会占用更多的内存?字符串或ByteArray? [英] C#: What takes up more memory? A string or bytearray?

查看:395
本文介绍了C#中:什么会占用更多的内存?字符串或ByteArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#:是什么占用更多的内存?一个字符串或字节?

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?

推荐答案

字节数组。这将存储您的文本为ASCII(每个字符1字节)字符,而.NET字符串使用统一code这是更大的。但是请记住,.NET字符串可能更有用,并在大型应用程序的差别可能不会产生巨大的变化。

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.

(请注意,如果你只是用ASCII字符在.NET字符串,然后字符将仍然只有1个字节)

(note also that if you just use ASCII characters in your .NET string then the characters will still only be 1 byte each)

这篇关于C#中:什么会占用更多的内存?字符串或ByteArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆