0

I have a coordinate class with two ints that has a method to show the coordinate as "A1" or "C5".

For the letter I'm using a char, and I don't know what's the best way to concatenate the two variables.

The return of the method looks like this:

//letter is a char
//line is an int
return letter+""+line;

I'm using "" because it implicitly casts the char and the int as strings. If letter was a string I could just do return letter+line; but with a char the implicit conversion doesn't work.

I'm not really satisfied with this way, should I? What would be a cleaner way to do it?

Teleporting Goat
  • 417
  • 1
  • 6
  • 20

2 Answers2

2

Try this

return $"{letter}{line}";
Antoine V
  • 6,998
  • 2
  • 11
  • 34
  • Tthat's a great way to do it. It's a little low on explanations though, so I'm linking [this answer on the dollar sign](https://stackoverflow.com/questions/32878549/whats-with-the-dollar-sign-string) which explains it very well. – Teleporting Goat Oct 25 '18 at 15:30
0

This I guess is the best way to do it:

return String.Concat(letter, line);
Adarsh Ravi
  • 893
  • 1
  • 16
  • 39