I've been using C# for a little while now, but mostly in Unity. I've only recently started just simply writing C# code in Visual Studio.
I was simply playing around with implementing a Queue with an array and was doing a bit of research into constructors. In my Queue class I had a constructor that set up an instance for the array itself:
public class Queue
{
int front = 0;
int rear = -1;
int size = 0;
const int maxSize = 5;
int[] queue;
public Queue()
{
queue = new int[maxSize];
}
//rest of class
}
Then in the class that calls creates a queue and does some testing etc. with it I used a main method:
class program
{
static void Main()
{
Queue myQueue = new Queue();
myQueue.enQueue(1);
myQueue.enQueue(2);
myQueue.enQueue(3);
myQueue.enQueue(4);
myQueue.enQueue(5);
myQueue.enQueue(6);
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
myQueue.enQueue(6);
myQueue.enQueue(7);
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
Console.WriteLine(myQueue.deQueue());
Console.ReadLine();
}
}
Now my question is what is the difference between these two methods? At the moment to me they are simply "the method that is invoked when the program is initially run" sort of like the equivalent to the Start()
method in Unity which is what I'm used to.