I have the below code:
using System;
using System.Collections.Generic;
public class XTRAsystem
{
public string version
{ get; set; }
public XTRAapi api
{ get; set; }
public XTRAsystem(string system_version)
{
this.version = system_version;
XTRAapi api = new XTRAapi(Guid.NewGuid());
Console.WriteLine("New XTRA system (" + this.version + ") initialized.");
}
public class XTRAapi
{
public Guid id
{ get; set; }
public string name
{ get; set; }
public XTRAapi(Guid Id)
{
this.id = Id;
Console.WriteLine("New T24 API created.");
}
}
}
public class testCase
{
public int caseNumber
{ get; set; }
public List<string> data;
public XTRAsystem refSystem
{ get; set; }
public testCase()
{
data = new List<string>();
Console.WriteLine("New Test Case created.");
}
}
There is a reason that the two classes above are nested. Now, on my Main, in Program, the below code produces Null reference exception. Could someone help me?
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start..");
XTRAsystem mySystem = new XTRAsystem("Mickey");
testCase[] myTest = new testCase[100];
Console.WriteLine("Capacity is {0}", myTest.Length);
// 'Object reference not set to an instance of an object' for all the below
myTest[0].caseNumber = 1;
myTest[0].data.Add("first test");
myTest[0].data.Add("second test");
myTest[0].data.Add("third test");
myTest[0].refSystem = mySystem;
}
}
}
By your expertise and experience, is there any other way to produce the functionality that now produces error (line myTest[0]... etc.) Thank you very much