Operator '&&' cannot be applied to operands of type 'string' and 'string'

I'm totally new to C# so your help is much appreciated.
Here's what I have.
string strSummary;
if(txtPhnNumber.Text != "" ){
strSummary += "\nPhone Number: " && txtPhnNumber.Text;
}
The error comes back saying, "Operator '&&' cannot be applied to operands of type 'string' and 'string'" whe rebuilding the site. I'm using Visual Web Developer Express edition.
[488 byte] By [ljCharlie] at [2007-12-20]
# 1
Hi,
if you want to "add" (join) two strings you need to use the operator +:
strSummary += "\nPhone Number: " + txtPhnNumber.Text;
n0n4m3 at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

n0n4m3 wrote:
Hi,
if you want to "add" (join) two strings you need to use the operator +:
strSummary += "\nPhone Number: " + txtPhnNumber.Text;

Just FYI, joining two strings together is called "concatenating" the strings. Also, since C# strings are immutable, you're better off using a StringBuilder object to do this.

Example:

using System.Text;

...

const string phoneNumberLiteralText = "\nPhone Number: ";

StringBuilder summary = new StringBuilder();

<Loop construct here>

summary.Append(phoneNumberLiteralText);
summary.Append(txtPhnNumber.Text);

</Loop construct>

RobertC.Barth at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 3

Robert, careful with the StringBuilder suggestion, it isn't always better. I suggest you read

http://www.yoda.arachsys.com/csharp/stringbuilder.html

MattiasSj?gren at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
Many thanks for all of your help. I'll try the + operator. As for the string builder...I'll have to read more about it because I have never used or heard it before.
ljCharlie at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
You want to concat some string, you can do this in many ways. Concatting can be really expencive when you work with large strings or when you have a lot to concat. I normally use a StringBuilder when i have more then 5 concats.

For your code the easiest solution is to use the + operator to append the first string to the second string and the += operator to append this result to the strSummary:


string strSummary;

if(txtPhnNumber.Text != "" )
{
strSummary += "\nPhone Number: " + txtPhnNumber.Text;
}

PJ.vandeSande at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...