CSharp - What is the output: Out variables discards?

Question

What is the output of the following code?

using System;
class Test
{
   static void Split (string name, out string firstNames,out string lastName)
   {
          int i = name.LastIndexOf (' ');
          firstNames = name.Substring (0, i);
          lastName   = name.Substring (i + 1);
    }

    static void Main()
    {
         string a, b;
         Split ("this is a test", out a, out _);
         Console.WriteLine (a);                      
         Console.WriteLine (b);                      
    }
}


Click to view the answer

Console.WriteLine (b);    //compile time error

Note

The code uses Out variables discards to ignore the second parameter.

b is not being set a value before using.

Related Quiz