.NET 字符串的最大可能长度是多少? [英] What is the maximum possible length of a .NET string?

查看:45
本文介绍了.NET 字符串的最大可能长度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET 中可以创建的最长字符串是多少?据我所知,String 类的文档对这个问题没有提及,因此权威的答案可能需要一些内部知识.在 64 位系统上最大的变化是什么?

What is the longest string that can be created in .NET? The docs for the String class are silent on this question as far as I can see, so an authoritative answer might require some knowledge of internals. Would the maximum change on a 64-bit system?

[这更多是出于好奇而不是实际用途 - 我不打算创建任何使用巨大字符串的代码!]

[This is asked more for curiosity than for practical use - I don't intend to create any code that uses gigantic strings!]

推荐答案

理论极限可能是 2,147,483,647,但实际极限远不及此.由于 .NET 程序中的任何单个对象都不能超过 2GB,并且字符串类型使用 UTF-16(每个字符 2 个字节),因此您能做的最好的事情是 1,073,741,823,但您可能永远无法分配在 32 位机器上.

The theoretical limit may be 2,147,483,647, but the practical limit is nowhere near that. Since no single object in a .NET program may be over 2GB and the string type uses UTF-16 (2 bytes for each character), the best you could do is 1,073,741,823, but you're not likely to ever be able to allocate that on a 32-bit machine.

这是其中一种情况 "如果您要问,您'可能做错了什么."

这篇关于.NET 字符串的最大可能长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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