Difference between revisions of "QueueOfTiles Constructor"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Added code and a brief summery)
 
m (Clarified lack of void)
 
Line 1: Line 1:
This is a constructor, it is a method sharing the same name as the class but it has no return type. A constructor is the very first method that runs whenever an instance is created.  
+
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=
 
=Code=
 
<syntaxhighlight lang = "csharp">
 
<syntaxhighlight lang = "csharp">

Latest revision as of 11:42, 14 November 2017

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();