2 Replies - 570 Views - Last Post: 11 January 2013 - 07:33 AM Rate Topic: -----

#1 eiger3970  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-November 11

Error 18 Only assignment, call, increment, decrement, and new object e

Posted 10 January 2013 - 07:42 PM

Hi,
I'm trying to check if the row and column are within the bounds of the rectangular array.
If they are within the bounds, it returns what is at the board at position row, column.
I can' return what is at the board at position row, column?

public static int[,] Get(int row, int column)
{
if (row <= 0 || row > 9 && column <= 0 || column > 9)
    {
        get{return row;}
        get{return column;}
    }

    else

    {
    return null;
    }
}   



I've tried:
// Reference: http://msdn.microsof...HARP%29&rd=true, viewed 201301111220. // public int row{get;} // Console.WriteLine(int row, int column); // Console.WriteLine(int[,] row, int [,] column); // Console.WriteLine(row[,], column[,]); // Console.WriteLine(int row, column); // Console.WriteLine(int[,] row, column); // Console.WriteLine(int[,] row, int[,] column);

// public int column{get;} // Reference: http://msdn.microsof...22.NETFRAMEWORK,VERSION%3dV4.0%22%29%3bk%28DevLang-CSHARP%29&rd=true, viewed 201201111216.

Is This A Good Question/Topic? 0
  • +

Replies To: Error 18 Only assignment, call, increment, decrement, and new object e

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3470
  • View blog
  • Posts: 10,703
  • Joined: 05-May 12

Re: Error 18 Only assignment, call, increment, decrement, and new object e

Posted 10 January 2013 - 08:00 PM

I think you are looking for something like this:
enum Cell { Empty, X, O };

public class TicTacToe
{
    Cell[,] grid = new Cell[3,3];

    Cell this[int row, int column]
    {
        get
        {
            if (row < 0 || row > 2)
                throw IndexOutOfRangeException("row");
            if (column < 0 || column > 2)
                throw IndexOutOfRangeException("column");

            return grid[row, column]; 
        }
    }
}


This post has been edited by Skydiver: 10 January 2013 - 08:01 PM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,661
  • Joined: 02-June 10

Re: Error 18 Only assignment, call, increment, decrement, and new object e

Posted 11 January 2013 - 07:33 AM

Quote

public static int[,] Get(int row, int column)
{
    if (row <= 0 || row > 9 && column <= 0 || column > 9)
    {
        get{return row;}
        get{return column;}
    }
...
}   




Somehow you have gotten the idea that you can have more than one return from a method. I can't even imagine what you must be thinking happens within the calling method that would receive this. Do you think it somehow waits until 2 values are returned?

You also seem to have mixed up the use of a get {} which comes from a property and are trying to use it within a method.

And you don't see that even if all this somehow magically worked you are only returning the same values the method received.

Its obvious that all this code stuff is just gibberish to you. I think you need to stop writing code and review your textbook from page one. If you don't understand any of the underlying concept then you aren't going to be able to write code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1