I’ve an array property called Value:
public string[,] Value { get; set; }
I want to call the Save() method when any value of the array (not the entire array) has changed.
Is there an easy way to implement it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not really. Arrays are very primitive types and do not notify you when things change.
The best you can do is create a custom type that acts like a 2D array, but in addition it raises an event when an element has changed. Your current class would then subscribe to this event and call
Save().Some additional comments:
Save()when the indexer’s setter is called. See below.public string this[int x, int y] { get { return this.localArray[x,y]; } set { this.localArray[x,y] = value; this.Save(); } }