Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
What should be instead of "value"?


C#
bool[,,] A2;

bool[,,] A
{
  get { return A2[value,value,value]; }

  set  
    {
        if(A2[value,value,value]!=value] 
       {
         progressMade=true;
         A2[value,value,value]=value;
       }
    }
}
Posted

I think this is kind of what you want; if it's not, I'd be curious to hear from you:
C#
public class IndexedArray
{
    public bool[,,] A2 { set; get; }

    public bool progressMade { set; get; }

    public List<int> lastChangedIndexes { set; get; }

    public IndexedArray(int d1, int d2, int d3)
    {
        progressMade = false;
        A2 = new bool[d1,d2,d3];
        lastChangedIndices = new List<int>();
    }

    // the indexer
    public bool this[int x, int y, int z]
    {
        get  { return A2[x, y, z]; }

        set
        {
            progressMade = A2[x, y, z] != value;

            if (progressMade)
            {
                lastChangedIndices .Add(x);
                lastChangedIndices .Add(y);
                lastChangedIndices .Add(z);

                A2[x, y, z] = value;
            }
        }
    }
}
Test:
C#
IndexedArray testArrayProp = new IndexedArray(3, 4, 5);

testArrayProp[1, 2, 3] = true;

bool check = testArrayProp[1, 2, 3];

var changedIndices = testArrayProp.LastChangedIndices;
I would not use this type of solution to the problem of how you manage an Array, and keep track of change ... if that's what you are really after here.

Of course, you can't inherit from 'Array, or use 'Array as a constraint in a Generic Class, because Array is sealed. Depending on the circumstances I would go for using Lists.

At the point you wanted to dynamic notifications of changes, you could implement INotifyPropetyChanged, rather than use the non-dynamic tracking variables used here.
 
Share this answer
 
C#
class AX
        {
            public bool this[int x, int y, int i]
            {
                get
                {
                    return A2[x, y, i];
                }

                set
                {
                    if (A2[x, y, i])
                        progressMade = true;

                    A2[x, y, i] = value;
                }
            }
        }

AX A = new AX();

static bool[, ,] A2 = new bool[9, 9, 9];
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 12-Jan-15 19:25pm    
5ed.
—SA
john1990_1 12-Jan-15 19:32pm    
?
Sergey Alexandrovich Kryukov 12-Jan-15 19:42pm    
My vote of 5 for the answer. By mistake; I did not look properly. See my last comment.
—SA
BillWoodruff 12-Jan-15 23:30pm    
Hi Sergey, this is an answer by the OP to their own question that contains code that won't compile, that contains obvious errors, and code that would do nothing if it did compile. How can you possibly vote it #5 ?
Sergey Alexandrovich Kryukov 12-Jan-15 23:52pm    
I was too fast, though that the idea so obvious that it would be impossible to create the code which cannot compile. Thank you for pointing out my mistake.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900