c# - "is a field but is being treated like a type" error -
this question has reply here:
“is field , used type” error 2 answersi trying create array of lists of structs. initialise list of structs so:
list<mystruct> mydata = new list<mystruct>();
but when seek create array (example beingness array 1 element), ie
list<mystruct>[] mydata = new list<mystruct>[1]; mydata[0] = new list<mystruct>();
i error saying
mydata
field beingness treated type.
i've looked @ reply don't understand difference is: answer
is there fundamental difference how c# treats structs, compared integers?
thanks help.
included clarity, code in full:
namespace my_project { using tradingtechnologies.ttapi; public partial class form1 : form { list<timeandsalesdata>[] mydata = new list<timeandsalesdata>[10]; //here believe making mistake: mydata[1] = new list<timeandsalesdata>(); //i error mydata field beingness used type. public form1() { initializecomponent(); } } } namespace tradingtechnologies.ttapi { // summary: // represents single trade transaction instrument public struct timeandsalesdata { public timeandsalesdata(instrument instrument, bool isoverthecounter, cost tradeprice, quantity tradequantity, tradedirection direction, datetime timestamp); // summary: // gets side trade public tradedirection direction { get; } // // summary: // gets instrument associated trade transaction public instrument instrument { get; } // // summary: // gets whether trade over-the-counter (otc) public bool isoverthecounter { get; } // // summary: // gets time trade occurred public datetime timestamp { get; } // // summary: // gets cost @ trade occurred public cost tradeprice { get; } // // summary: // gets quantity traded in trade transaction public quantity tradequantity { get; } } }
you have code floating around within class definition. needs within of method or constructor of sort:
public partial class form1 : system.windows.forms.form { public form1() { initializecomponent(); list<timeandsalesdata>[] mydata = new list<timeandsalesdata>[10]; mydata[1] = new list<timeandsalesdata>(); } }
if want mydata
field , not local variable, need just declare @ top level of class, initialize in constructor/method.
c#
No comments:
Post a Comment