c# - 引用类型,StringBuilder

标签 c#

我有一个字符串 errMsg 在读取输入文件后打印。验证完成后,如果 success==false 它调用方法 PrintErrorMessage(string)

//Validations 
//First Validation: checks the value of input string realization. 
success = Numerical.Check("Realizations", inputs.realizations.ToString(), out ltester, out errMsg);
sb.AppendLine(errMsg);

//Second Validation: checks the value of the input string diameter.
success = Numerical.Check("Pipe Outside Diameter", inputs.pipeOD.ToString(), out dtester, out errMsg);
sb.AppendLine(errMsg); 
if (!success)
{
    PrintErrorMessage(success, errTitle, sb.ToString());
}

这是我打印错误的方法:

Streamwriter swpt = new Streamwriter(....);
private void PrintErrorMessage(bool success, string errTitle, string errMsg)
{
    if (!success)
    {
        swRpt.WriteLine(errTitle + errMsg);
    }
}

问题是这样的:我可以使用 ref 类型并将其传递到 PrintErrorMessage 函数中,而不是在每次验证后的每一步都附加 StringBuilder 并且将它附加到那里?

最佳答案

Instead of appending the stringbuilder at each an everystep after each validation, can I use a ref type and pass it in the PrintErrorMessage function and append it there

您可以不带 ref 传递它并附加到它。 StringBuilder 是一个引用类型

关于c# - 引用类型,StringBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9642093/

相关文章:

c# - Visual Studio 2010 C# 智能感知代码片段的有用列表

c# - 对象模型设计选择

c# - 在 C++ 应用程序的另一个目录中使用 C# 库

c# - PropertyDescriptor 和 WPF 绑定(bind)机制

c# - 在代码中设置时 SelectedValue 不更新

c# - 如何以编程方式控制 Windows 7 调音台?

java - AES 加密的 88 字节输出

c# - var 如何知道未定义的类型?

c# - 用于在多个平台上实现 AdNetworks 的抽象工厂模式

c# - 如何将字符串与列表框中的所有项目进行比较?