Извините, я не знаю, как выразить свой вопрос,
у меня есть код на C #:
public class Cell
{
public bool boo;
public bool boo2;
public int xPos;
public int yPos;
public Cell(int xPosition, int yPosition)
{
xPos = xPosition;
yPos = yPosition;
}
public void SomeMethod()
{
boo = false;
boo2 = true;
}
public void SomeMethod2()
{
boo = true;
boo2 = false;
}
}
и я создаю экземпляр, подобный этому:
public static Cell[,] w;
public Cell c
w = new Cell[5,5]
...
//some other code
и результат из кода выше, я могу получить доступ к методу и свойствам из класса ячеек, я пытаюсь сделать тот же код в F #
type Cell(xPosition:int,yPosition:int) =
let mutable m_boo = false
let mutable m_boo2 = false
//x and y position of cell in picture box
let mutable xPosition = 0
let mutable yPosition = 0
new(xPosition,yPosition) = new Cell(xPosition,yPosition)
new() = new Cell(0,0)
member this.xPos with get() = xPosition
and set newX = xPosition <- newX
member this.yPos with get() = yPosition
and set newY = yPosition <- newY
member this.boo with get() = m_boo
and set newBoo = m_boo <- newBoo
member this.boo2 with get() = m_boo2
and set newBoo2 = m_boo2 <- newBoo2
member this.SomeMethod() =
this.boo <- false
this.boo2 <- true
member this.SomeMethod2() =
this.boo <- true
this.boo2 <- false
и я пытаюсь создать экземпляр:
let worldGrid:Cell[,] = Array2D.zeroCreate 5 5
worldGrid.[0,0].SomeMethod2()
Результат, когда скомпилированный код:
System.NullReferenceException: ссылка на объект не установлена для экземпляра объекта
что-то не так в моем коде или я делаю это неправильно? Надеюсь, что с прочитанным кодом поможет понять мой вопрос.