1

I have an array that gets accessed in very complex ways; is it possible to break in visual studio 2008 when a certain element of the array is accessed? Or the array itself is accessed?

Thanks.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
Jacko
  • 12,665
  • 18
  • 75
  • 126

2 Answers2

1

You can't set a breakpoint for when a certain element in the array is accessed, but you can set a breakpoint for when the array is accessed by changing it to a property, and putting the breakpoint in the get accessor.

So change this:

public string[] myArray;

To this:

private string[] myArray;
public string[] MyArray
    {
        get
        {
            return myArray; //put breakpoint here.
        }
        set
        {
            myArray = value;
        }
    }
Greg Sansom
  • 20,442
  • 6
  • 58
  • 76
1

You can use conditional breaks. Meaning that say you have a method where you pass as an argument the index of the array to be accessed, you can then use a condition to break when index is X.

To insert a conditional break right click on the break point an select condition.

Luis
  • 5,979
  • 2
  • 31
  • 51