Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I'm making a Sudoku game.

The code below works perfectly but I want to name it other than "this".

I can access it now by making: this[x1,y1,s1]

What I have tried:

bool[,,] aVt = new bool[9, 9, 9];
bool this[int x, int y, int s]
            {
                get { return aVt[x, y, s]; }
                set
                {
                    if (value == false)
                    {
                        if (aVt[x, y, s])
                        {
                            progressMade = true;
                        }
                    }
                    aVt[x, y, s] = value;
                }
            }
Posted
Updated 1-Jul-17 5:46am
v4

Do you mean something like this (ehh, not this)?
public int[,,] PropertyName
{
    get
    {
        return aVt;
    }

    set
    {
        // ...
        aVt = value;
    }
}
 
Share this answer
 
Comments
john1990_1 1-Jul-17 10:16am    
can i use it like this: propertyName[x1,y1,s1]=true;?
and it does: aVt[x1,y1,s1]=true; and does my code above?
Dave Kreskowiak 1-Jul-17 10:35am    
What happens when you TRY IT?
[no name] 1-Jul-17 10:35am    
What does 'aVt[x1,y1,s1]=true' mean? An array with 3 integers (or bools) doesn't have a 'true' property by itself.
If you explain what it is you want to do, perhaps I can help you some more...

PS. You can change 'PropertyName' to a name you like.
john1990_1 1-Jul-17 10:42am    
I know I can change propertyName but I'm sorry I was almost sure that's not what I'm looking for and that's why I didn't try, I need to check if the new value to the bool in the three dimensional array is false and the existing value is true and set progress made in solving the Sudoku to true, in the solution you gave I cant check that, please see my code, I want an exact copy not named: "this".
I made it...

classaV aV=new classaV();

        class classaV
        {
            // Declare an array to store the data elements.
            bool[,,] aVt = new bool[9, 9, 9];

            // Define the indexer to allow client code to use [] notation.
            public bool this[int x, int y, int s]
            {
                get { return aVt[x, y, s]; }
                set
                {
                    if (value == false)
                    {
                        if (aVt[x, y, s])
                        {
                            progressMade = true;
                        }
                    }
                    aVt[x, y, s] = value;
                }
            }
        }
 
Share this answer
 
I see. You're using an indexer and you can't translate 'this' to a property because properties don't allow multiple arguments.
If you don't want to use your new class: to get the value just use: bool value = aVt[x, y, z]; and to set the value use e.g.: SetaVt(1, 2, 3, true);
C#
public void SetaVt(int x, int y, int z, bool value)
{
    if (value == false)
    {
        if (aVt[x, y, s])
        {
            progressMade = true;
        }
    }
    aVt[x, y, s] = value;
}
 
Share this answer
 
Comments
john1990_1 1-Jul-17 11:50am    
Thanks a lot...
[no name] 1-Jul-17 11:56am    
You're welcome. Good luck with your game!

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