I wrote a function that takes an array of 10 integers (from 0 to 9) that returns a string of those numbers as a phone number.
Example:
Kata.CreatePhoneNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}) // => returns "(123) 456-7890".
The program is fully working, but I want to make this code shorter and clearer.
class Program
{
static void Main()
{
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
CreatePhoneNumber(numbers); // => returns "(123) 456-7890"
}
public static string CreatePhoneNumber(int[] numbers)
{
return ($"({numbers[0]}{numbers[1]}{numbers[2]}) {numbers[3]}{numbers[4]}{numbers[5]}-{numbers[6]}{numbers[7]}{numbers[8]}{numbers[9]}");
}
}