1

When I use C# Array.ConvertAll, the variable in the body of the converter function is not visible any more in the debugger in Visual Studio 2017.

For example in:

public static void    Test()
{
    Vector3[] OriginalArray = new Vector3 [3]{ new Vector3(1,2,3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)};
    int[] Indices = new int[2] { 2, 1};

    Vector3[] SelectedArray = Array.ConvertAll(Indices, index => OriginalArray[index]);
}

The variable OriginalArray is not visible in the debugger "Local"/"Autos"/"Watch"-window. While the variable is visible when used in the manner as in the code below:

public static void Test2()
{
    Vector3[] OriginalArray = new Vector3[3] { new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9) };
    int[] Indices = new int[2] { 2, 1 };

    List<Vector3> subverticesList = new List<Vector3>();
    foreach (int index in Indices)
    {
        subverticesList.Add(OriginalArray[index]);
    }
    Vector3[] SelectedArray = subverticesList.ToArray();
}

See attached screenshots: Visual-Studio-2017-Array-ConvertAll-Not-Showing-Variable-01.png Visual-Studio-2017-Showing-Variable-with foreach-loop-02.png

isgoed
  • 724
  • 6
  • 12
  • 1
    The first case reminds me of debugging an optimised build. – Richard Mar 09 '20 at 11:27
  • Yes, but you can see in the screenshot that it is in Debug configuration. The variable is in both cases on the stack. Or is some internal code being run? – isgoed Mar 09 '20 at 12:47

0 Answers0