Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ref type, StringBuilder

Tags:

c#

I have a string errMsg to be printed after an input file is read. After the validations are done, if success==false it calls the method 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());
}

Here's the method where I print the error:

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

The question is this: Instead of appending the StringBuilder at each and every step after each validation, can I use a ref type and pass it in the PrintErrorMessage function and append it there?

like image 332
user575219 Avatar asked Sep 11 '26 15:09

user575219


1 Answers

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

You can pass it without ref and append to it. StringBuilder is a Reference Type

like image 114
Henk Holterman Avatar answered Sep 13 '26 03:09

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!