相关疑难解决方法(0)

在.NET/BCL源代码中混淆注释"string.Empty"的含义?

我试图理解为什么string.Emptyreadonly和不是const.我看过这篇帖子,但我不明白微软写的关于它的评论.正如Jon Skeet 在评论中所写的那样"我不知道 - 对我来说这没有多大意义,说实话......"

共享源公共语言基础结构2.0版本.string.cs位于sscli20\clr\src\bcl\system\string.cs中

// The Empty constant holds the empty string value.
//We need to call the String constructor so that the compiler doesn't mark this as a literal.
//Marking this as a literal would mean that it doesn't show up as a field which we can access 
//from native.
public static readonly String Empty = ""; 
Run Code Online (Sandbox Code Playgroud)

我在这里看不到任何String构造函数调用,而且,它被标记为文字 - ""

有人可以用明文解释我,评论意味着什么,为什么string.Empty readonly不是const …

.net c# compiler-construction string base-class-library

33
推荐指数
1
解决办法
2082
查看次数

如何防止字符串被拦截

我的理解(可能是错误的)是在c#中创建一个字符串时它会被插入"实习池".这保持了对字符串的引用,以便多个相同的字符串可以共享操作内存.

但是我正在处理很多很可能是唯一的字符串,我需要在完成每个字符串时将它们从操作内存中完全删除,我不知道如何删除缓存的引用以便垃圾收集器可以从内存中删除所有字符串数据.如何防止字符串被嵌入此缓存中,或者如何清除它/或从中删除字符串以便它确实从操作内存中删除?

c# memory

11
推荐指数
2
解决办法
2535
查看次数

C#如何存储字符串

我想知道在哪里或如何存储由"Hello World"编写的字符串值.

例如:

例1:

radLabel1.Text = "Hello";
radLabel2.Text = "Hello";
radLabel3.Text = "Hello";
Run Code Online (Sandbox Code Playgroud)

例2:

string strTemp = "Hello";
radLabel1.Text = strTemp;
radLabel2.Text = strTemp;
radLabel3.Text = strTemp;
Run Code Online (Sandbox Code Playgroud)

我知道第二种方式是最有用的,我这样做,但我想知道示例1的字符串是如何存储在RAM中的.我想虽然它们是相同的,但是在RAM中为它们创建了三个地方来存储它们.但是在示例2中,仅为示例2的字符串创建了一个位置,并且访问了该地址.我对吗 ?你能解释一下这个或将变量存储在RAM中吗?

c#

2
推荐指数
1
解决办法
193
查看次数

Comparing strings in a loop using Is Operator

Is Operator works fine when comparing two strings like:

Dim str1 As String = "TagnameX"
Dim str2 As String = "TagnameX"

Dim strChk as boolean = str1 Is str2
'strChk returns True

Run Code Online (Sandbox Code Playgroud)

But when one of the strings is extracted by Substring it returns false ! as below:

Dim str1 As String = "t#1TagnameX"
Dim str1Extract As String = str1.Substring(3, 8)
Dim strArr() = {"Tagname1", "Tagname2", "TagnameX"}  

 For i = 0 To strArr.Length - 1
      If strArr(i) Is str1Extract Then …
Run Code Online (Sandbox Code Playgroud)

vb.net

2
推荐指数
1
解决办法
95
查看次数