已经过的String.intern的价值? [英] Has String.Intern had the value?

查看:190
本文介绍了已经过的String.intern的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的String.intern 具有稍后可检索的字符串,特殊池。

String.Intern has a special pool for strings which can later be retrieved.

有什么办法,我知道,指定字符串的取自池,并没有新创建的? 例如:

Is there any way for me to know that the specified string was taken from the pool , and was NOt newly created ? example :

string s1 = "MyTest"; 
string s2 = new StringBuilder().Append("My").Append("Test").ToString(); 
string s3 = String.Intern(s2); 
Console.WriteLine((Object)s2==(Object)s1); // Different references.
Console.WriteLine((Object)s3==(Object)s1); // The same reference.

S3裁判VAL 从池中获取

有什么办法,我知道了吗?

is there any way for me to know it ?

推荐答案

您可能有一些运气的 IsInterned 方法,它返回如果字符串不拘留,并返回一个参考,如果它是从池中获取。但是,此行为将取决于运行,并可能不会产生你所期望的。

You might have some luck with the IsInterned method, it returns null if the string wasn't interned, and returns a reference if it was taken from the pool. However, this behaviour will depend on the runtime, and might not yield what you expect.

这篇关于已经过的String.intern的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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