Monday, May 24, 2010

How do you concatenate strings in C#?

I need to concatenate three strings called Month, Balance, and Interest. What's the correct syntax in C#?

How do you concatenate strings in C#?
the simplest answer to this would be simply doing the following


String trial ;


trial =+ "what ever I want to add here";


trial =+ "here i add some more to the string";





Hope this helps
Reply:using System.Text;


...


StringBuilder sbStatement = new StringBuilder();


sbStatement.Append(Month);


sbStatement.Append(" ");


sbStatement.Append(Balance);


...


string strStatement = sbStatement.ToString();


... Report It

Reply:Hi, its me again. There is a Concat function of the String class or you can use the overloaded + operator.





String.Concat(Month, Balance.ToString());





strVariable = Month + Balance.ToString() + Interest.ToString();





Hope this is what you were looking for.


No comments:

Post a Comment