Why is my C# if statement code not working?

I can't figure out why this If statement doesn't work.

if (textBox2.Text.Contains(".xwm") && textBox4.Text.Contains(".xwm") == true) 
{
    textBox4.Text.Replace(".xwm", ".wav");
}
else if (textBox2.Text.Contains(".wav") && textBox4.Text.Contains(".wav") == true) 
{
    textBox4.Text.Replace(".wav", ".xwm");
}

What its supposed to do is replace the file extension in textBox4 with the opposite one in this case I'm making a XWM to Wav Converter. so IF textbox2 and textBox4 contain the same file extension it will change the one in textBox4 to the other file type.

Why isn't it working.

PS: I'm a noob on C# so explain it as best as you can to a noob

Jon Skeet
people
quotationmark

You're calling Replace on a string, but then not doing anything with the result. Strings are immutable in C# - any methods which sound like they might be changing the string actually just return a reference to a new string (or potentially a reference to the old one if no change was required). So calling Replace (or similar methods) and then ignoring the result is always pointless.

I suspect you want:

textBox4.Text = textBox4.Text.Replace(".xwm", ".wav");

As an aside, I'd also get rid of the == true, and quite possibly extract all the read accesses to the textboxes:

// Rename these as appropriate - and rename the textBox* variables so the names
// explain the purpose.
string source = textBox2.Text;
string target = textBox4.Text;
if (source.Contains(".xwm") && target.Contains(".xwm"))
{
    textBox4.Text = target.Replace(".xwm", ".wav");
}
else if (source.Contains(".wav") && target.Contains(".wav"))
{
    textBox4.Text = target.Replace(".wav", ".xvm");
}

(I suspect there are even better ways of expressing what you're trying to achieve, but at the moment we don't know what that is...)

people

See more on this question at Stackoverflow