QueueOfTiles Constructor

From TRCCompSci - AQA Computer Science
Revision as of 11:42, 14 November 2017 by Jared (talk | contribs) (Clarified lack of void)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a constructor, it is a method sharing the same name as the class but it has no return type (not even void). A constructor is the very first method that runs whenever an instance is created.

Code

			public QueueOfTiles(int MaxSize)
			{
				this.MaxSize = MaxSize;
				this.Rear = -1;
				for (int Count = 0; Count < this.MaxSize; Count++)
				{
					Contents.Add("");
					this.Add();
				}
			}

This is the constructor without any other code, it requires a int.

			public QueueOfTiles(int MaxSize)
			{
			}

This sets the instance MaxSize to the passed in MaxSize.

				this.MaxSize = MaxSize;

This sets the instace rear to -1.

				this.Rear = -1;

This is a standard for loop that goes through until it has reached the MaxSize.

				for (int Count = 0; Count < this.MaxSize; Count++)
				{
				}

This adds an empty string to the contents list and then calls the Add method to correct the rear pointer.

					Contents.Add("");
					this.Add();