I need to mash a list of strings together using one or two properties from a list of objects, but dependant on a bit of logic. Each item in the list should be the string value of property 1 and property 2 joined together, separated by a hyphen. UNLESS property 1 has the same string value as property 2, in which case the item will simply be property 1. Just to clarify, all the objects are the same type and the two properties are both string values.
Here’s an example to illustrate it just in case I didn’t make sense..
Object 1: Prop 1 = "Object 1", Prop 2 = "Object 1" // Same value
Object 2: Prop 1 = "Object 2", Prop 2 = "Obj 2" // Different
Resulting list =
[0] = "Object 1",
[1] = "Object 2-Obj 2"
Is there a “neat” way of doing that using a bit of Linq or something rather than looping through manually?
something like this?