vb.net - Declare New without using With or From -


i know if possible write multiple lines, equivalent of line bellow, instead of using , use multiple lines declare data.

dim price = new pricestruc() { _   .bids = new list(of prices)() {new prices() {.price = 1101, .size = 1}},   .offers = new list(of prices)() {new prices() {.price = 1102, .size = 1}}} 

you can add parameters constructor set properties when create instance. helpful object should exist when or property known. use in designer serialization, among others.

warning: taking far requested doesnt make code easier read

i dont know these are, made own , fixed of nomenclature (it looks prices has data 1 item, yet plural).

friend class price     public property value integer     public property size integer      public sub new()      end sub      public sub new(v integer, s integer)         value = v         size = s     end sub end class 

the simple constructor (no params) there because many serializers require one. depending on serializer, can set friend force code use overload , specify value , size when create new price object. useful when object has no right being created without key information. (you can still use in for each loops because not need new object that).

in case, value (named avoid price.price) , size might required elements, constructor overload convenience. use it:

dim p new price(1101, 1) 

now, objects can instanced without with. holder looks this:

friend class priceitem     public property bids list(of price)     public property offers list(of price)      public sub new()      end sub      public sub new(b list(of price), o list(of price))         bids = b         offers = o     end sub  end class 

there more it, name indicating bids , offers for, idea same: pass lists in constructor.

now can initialize price objects , priceitem using constructors:

dim prices = new priceitem(new list(of price)(new price() {new price(1101, 1),                                                            new price(1102, 1)}),                            new list(of price)(new price() {new price(1106, 7),                                                            new price(1104, 1)})) 

no with
no from

1101 , 1102 bid items, 1106 , 1104 offer items.

as said, doesnt make easier read, debug or code. perhaps makes sense price item passing lists priceitem ctor seems bit much. rather trying squeeze initialization, seems strike best balance between readability , conciseness:

dim pitem new priceitem pitem.bids = new list(of price)(new price() {new price(1101, 1), new price(1102, 1)}) pitem.offers = new list(of price)(new price() {new price(1106, 7), new price(1104, 1)}) 

no with
no from


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -