什么是.NET字符串的内部格式? [英] What's the internal format of a .NET String?

查看:121
本文介绍了什么是.NET字符串的内部格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一些pretty的字符串处理密集型code在C#.NET和有好奇一些乔尔Spolsky的文章中,我记得读了一段时间后:

I'm making some pretty string-manipulation-intensive code in C#.NET and got curious about some Joel Spolsky articles I remembered reading a while back:

http://www.joelonsoftware.com/articles/fog0000000319.html < BR> http://www.joelonsoftware.com/articles/Uni$c$c.html

那么,如何.NET办呢?每个字符两个字节?也有一些统一code字符^需要超过使得H ^ H ^ H ^ H ^ H code点。又是怎样连接codeD的长度是多少?

So, how does .NET do it? Two bytes per char? There ARE some Unicode chars^H^H^H^H^H code points that need more than that. And how is the length encoded?

推荐答案

在乔恩斯基特变成了这里是一个链接到他的优秀的琴弦博客在C#。

Before Jon Skeet turns up here is a link to his excellent blog on strings in C#.

在当前的实现中,至少,琴弦占用20+(N / 2)* 4个字节(四舍五入的n / 2下的值),其中n是字符串中的字符数。 string类型是不寻常的,对象本身的大小而定。

In the current implementation at least, strings take up 20+(n/2)*4 bytes (rounding the value of n/2 down), where n is the number of characters in the string. The string type is unusual in that the size of the object itself varies

这篇关于什么是.NET字符串的内部格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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