I'm trying to learn about statics ... let's say in the code below, I just need these 30 dogs to be available throughout my program.
What am I doing wrong here? It builds fine, but I'm getting the runtime error at line 15:
An unhandled exception of type System.NullReferenceException occurred in ConsoleApplication1.exe
Additional information: Object reference not set to an instance of the object.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string aName;
for (int x = 0; x < 30; x++)
{
aName = AppUtils.myDogs[x].Name; //<---- Errors here
}
}
}
public class MyDogClass
{
private string name;
private string breed;
private int age;
public MyDogClass()
{
this.name = "Unknown";
this.breed = "Unknown";
this.age = 0;
}
public string Name{ get{ return this.name;} set{this.name = value;}}
public string Breed{ get{ return this.breed;} set{this.breed = value;}}
public int Age{ get{return this.age;} set{this.age = value;}}
}
public static class AppUtils
{
public static MyDogClass[] myDogs = new MyDogClass[30];
}
}
Thanks guys. Its coming along slow ... but thanks to you guys, its starting to gel. Its just that I hit stuff like this every once ins a while.