What I am trying to achieve is to merge three strings. Two are provided as strings; firstname and lastname, while the third is a simple comma/space separator. Given the following lines of code:
//Working code var sep = ', '; var fullName = myNewBO[0].LastName + sep + myNewBO[0].FirstName; //Erronous code var fullName = myNewBO[0].LastName + ', ' + myNewBO[0].FirstName;
The string is returned to a cell in a DataGridView. While the first bit of code performs as expcted the latter does not. The string does not show in the cell as expected. Can someone tell me why the latter does not work? Also if you have a better solution to the problem please provide one.
EDIT: Solved. As suspected, and pointed out by several answers the problem was elsewhere in my code and the two alternatives do the exact same thing. Thanks for the syntax suggestions though 🙂
I suspect you have something else happening in your code, and you’re mistaking where the error is occurring. I can’t for the life of me see why those two would behave differently at all. I suggest you log the value after the assignment for both cases – I’m sure you’ll find they’re the same.