字典键中是否有任何字符限制? [英] Is there any character limitation in Dictionary Keys?

查看:130
本文介绍了字典键中是否有任何字符限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET中,我可以使用任何字符串作为字典键吗?这是模板引擎的一部分,我正计划允许用户添加其自定义标头和值.

In .NET can I use any string as a dictionary key? This is part of a templating engine and I'm planning allow users to add their custom headers and values.

标题将类似于"X的值"或分析和XYZ报告摘要",我担心它们是否会在稀有字符或类似的字符中出现异常.

Headers will be something like "Value of X" or "Summary of Analyse & XYZ Reports", I'm worried if they would get an exception in a rare character or something like that.

我假设有大小限制,但希望它大于256个字符. MSDN没有关于此主题的任何详细信息.

I assume there size limit but expecting it to be larger than 256 characters. MSDN hasn't got any details on the subject.

推荐答案

是的,它可以使用任何有效的字符串(限于数十亿字节).

Yes, it can use any valid string (which is limited to a couple billion bytes).

顺便说一句,您可能会传递一个自定义IEqualityComparer<T>,而该自定义IEqualityComparer<T>可能会传递给可能需要最大限制的Dictionary构造函数.

BTW, you might pass a custom IEqualityComparer<T> that you might pass to the Dictionary constructor which might require a maximum limit.

这篇关于字典键中是否有任何字符限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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