c# - Passing References -


I want to know a great way to pass class references from class.

Basically I have two classes in my check code:

One is an investigator game code.

  class checker codes {IchecherMove [,] Pieces; Public static counter counter; Checkers Checker; Public Zero ExecuteAll (ET column start, int linestart, int column end, int rowend) {checker = new checkers (); Gaming g = new game (pieces, column start, line start, column end, queue); // I live this reference down I want to pass in the method given in the Mewelidity Manager (); Checker.obtainGameReference (g); // I want to pass this method through this method.   

Other code form code:

  Public partial square checkers: form {public Checkers () {Initial group (); } Checkersode codefile = new checksod (); Private Zero Checkers_load (Object Sender, EventAgds E) {chessPics = Pattern (); PrintPieces (codeFile.FirstLoad ()); } Game GameFif; Public Zero gear reference (game g) // I want to get that reference here {gameRef = g; And this}}   

The problem is that it does not work. When I use GameRef reference it throws a nuller point exeption eg gameRef.piecePromotion (); GameRef;

but not:

  public game gamerph;   

What is Private Zero a1_Click (Object Sender, EventArgs e) {codeFile.ExecuteAll (rowStart, columnStart, rowEnd, columnEnd); // This piece every time I play a new picture box for GameRef.piecePromotion (); // This is executed next} After gameRef, after not being static, after executing the extol method once, the gameraf becomes empty (while it is terminated, it is assigned first).

ExecuteAll method here is:

  Public Zero ExecuteAll (int column start, int rostast, int column end, int rowend) {checker = new checkers (); Gaming g = new game (pieces, column start, line start, column end, queue); Checker.obtainGameReference (g); G.MoveValidityManager (); // A method calls for a class to be executed. No new example of checker class is being made inside the game class.   

It resets the game in any way, gets null via the code. So I checked the whole code, if I had created new checker type (my Vinfol partial square) but clicking on ctrl + f .. and i just got one example where i created an object reference.

Why does this game refresh, then this object specifies the context

I use the game player within the events ... I just play the game class and checkercode class only And I do not kill the code throught context. My reference is active only in pictureboxex click events:

  Private Zero a2_Click (Object Sender, EventArgs e) {if (NextTurn) {columnEnd = 1; Lineand = 2; CodeFile.ExecuteAll (rowStart, columnStart, rowEnd, columnEnd); // This method offers gameRef throughout, but in the end .... gameRef.piecePromotion (); // After the above method is finished it is reset to empty   

I saw the code in debug mode.

  Public Zero gear reference (game g) {gameRef = g; / G is not zero, the object is included in this Gamerf remains a null. }   

So when the code continues to run a few steps later. Form class / file (checkers)

  gameRef.piece promotion (); // gameRef is empty    

This is either gameRef is being used before being used, or it is set to be blank.

Since the class generates no sense without any meaning, I always have a part of class upperity (the set of conditions should always be true), and apply it to the constructor:

  Private Readonly Game _game; // is not read-only, but it is simple if it is public checkers (game play) {if (game == empty) throw new logic NullException (); _game = game; InitializeComponent (); }   

I'm also curious about why you're talking about "context" clearly. While correct, since the objects always reference, so talking about them in C # is unusual. This makes me wonder if the game can be a straight one, in which case other things are going wrong (you have a structure , But additional work is not required to maintain it).

Comments