区分一个字符串,字符串中的C#文字 [英] Distinguish a string literal from a string C#

查看:157
本文介绍了区分一个字符串,字符串中的C#文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要像做

IsItAStringLiteral("yes")
var v = "no";
IsItAStringLiteral(v)

通过明显的返回值。这可能吗?

With the obvious return value. Is it possible?

推荐答案

您可以使用string.IsInterned方法来确定给定的字符串是否在.NET实习生池。所有字符串自动添加到应用程序之前实习生池开始运行。

You can use the string.IsInterned method to determine whether a given string is in the .NET intern pool. All string literals are automatically added to the intern pool before the application begins running.

当然,这不会帮助您准确的问题。变量'V'将引用一个字符串常量,因此它也将出现在实习生池。为什么需要这样的功能?

Of course, that won't help you with your exact question. Variable 'v' will reference a string literal, so it too will appear in the intern pool. Why do you need such functionality?

这篇关于区分一个字符串,字符串中的C#文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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