I am trying to create an array of lists of structs. currently I would initialise the list of structs like so:
List<myStruct> myData = new List<myStruct>();
But when I try to create an array (example being an array with 1 element), ie
List<myStruct>[] myData = new List<myStruct>[1];
myData[0] = new List<myStruct>();
I get an error saying
myData
is a field but is being treated like a type.
I've looked at this answer but don't understand what the difference is: Answer
Is there some fundamental difference to how C# treats structs, compared to integers?
Thanks for your help.
Included for clarity, my code in full:
namespace My_Project
{
using TradingTechnologies.TTAPI;
public partial class Form1 : Form
{
List<TimeAndSalesData>[] myData = new List<TimeAndSalesData>[10];
//Here is where I believe I am making a mistake:
myData[1] = new List<TimeAndSalesData>();
//I get the error myData is a field but is being used as a type.
public Form1()
{
InitializeComponent();
}
}
}
namespace TradingTechnologies.TTAPI
{
// Summary:
// Represents a single trade transaction for an Instrument
public struct TimeAndSalesData
{
public TimeAndSalesData(Instrument instrument, bool isOverTheCounter, Price tradePrice, Quantity tradeQuantity, TradeDirection direction, DateTime timestamp);
// Summary:
// Gets the side for a trade
public TradeDirection Direction { get; }
//
// Summary:
// Gets the Instrument associated with this trade transaction
public Instrument Instrument { get; }
//
// Summary:
// Gets whether the trade is over-the-counter (OTC)
public bool IsOverTheCounter { get; }
//
// Summary:
// Gets the time the trade occurred
public DateTime TimeStamp { get; }
//
// Summary:
// Gets the price at which this trade occurred
public Price TradePrice { get; }
//
// Summary:
// Gets the quantity traded in this trade transaction
public Quantity TradeQuantity { get; }
}
}