You can merge/concatenate/combine two C# String fields using the +
operator, as shown in this example code:
1 2 3 4 5 6 7 8 9 10 |
static void Main(string[] args) { string firstName = "Tom"; string lastName = "Brown"; string fullName = firstName + lastName; Console.WriteLine(fullName); Console.ReadKey(); } |
Output:
The String fullName
now contains “TomBrown“. Note that there is no space between “Tom” and “Brown” because I didn’t put a space in there.
One way to add a space to the new string is to put one in there, as shown in this example:
1 2 3 4 5 6 7 8 9 10 |
static void Main(string[] args) { string firstName = "Tom"; string lastName = "Brown"; string fullName = firstName + " " +lastName; Console.WriteLine(fullName); Console.ReadKey(); } |
Output: