Creating variables from an array in C#

Viewed 37

What I'm trying to do is create four int at once using one array for the assignment.

public static void Run()
{
    Console.WriteLine("\nExercise 9:");
    Console.WriteLine("Enter four numbers > ");
    int[] nums = {Convert.ToInt32(Console.ReadLine()), 
                  Convert.ToInt32(Console.ReadLine()), 
                  Convert.ToInt32(Console.ReadLine()), 
                  Convert.ToInt32(Console.ReadLine())}
    int {num1, num2, num3, num4} = nums; // This is the line that I'm having trouble with.
}

What is the correct syntax for this type of assignment, if any?

0 Answers
Related