当使用字符串生成器时,当使用enum是输入时,我从append和append行函数中得到预期的结果,但是当enum被装箱时,append行和append函数给出不同的结果。StringBuilder Append和AppendLine为Enum提供了不同的结果
有谁能告诉我这可能是什么?
代码输出:
Append Enum: 1
Append Enum To String: One
Append Line Enum: 1
Append Line Enum To String: One
Append Object: One
Append Object To String: One
Append Line Object: 1
Append Line Object To String: One
代码:
Public Enum eTest
One = 1
Two = 2
End Enum
Sub Main()
Dim sb As New System.Text.StringBuilder()
Dim x = eTest.One
sb.Append("Append Enum: ").Append(x).AppendLine()
sb.Append("Append Enum To String: ").Append(x.ToString()).AppendLine()
sb.Append("Append Line Enum: ").AppendLine(x)
sb.Append("Append Line Enum To String: ").AppendLine(x.ToString())
Dim o As Object = x
sb.Append("Append Object: ").Append(o).AppendLine()
sb.Append("Append Object To String: ").Append(o.ToString()).AppendLine()
sb.Append("Append Line Object: ").AppendLine(o)
sb.Append("Append Line Object To String: ").AppendLine(o.ToString())
Console.WriteLine(sb.ToString())
'===============================
Console.ReadKey()
End Sub
将选项Strict On放在文件的顶部以消除差异。 – 2011-02-02 20:36:35