Search code examples
visual-studio-2008breakpoints

visual studio breakpoint when array item is accessed?


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.


Solution

  • 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;
            }
        }