c# - How to add a class property to a list of instances -


i'm newbie in c#. perhaps resolve i'm away of solution.

i have class:

public class testsetups : tabelactset {     public ilist<tabelactsca> valsetup { { return m_valsetup; } }     private static list<tabelactsca> m_valsetup;      /// constructor     public testsetups(idefinitionlist dlist)         : base(dlist)     {         m_valsetup = new list<tabelactsca>();     } } 

i have class called testcase

public class testcase : tabelacttes {     public ilist<testsetups> setups { { return m_setups; } }     private list<testsetups> m_setups; ...     testcase.m_setups = new list<testsetups>();      defs = gdl.getdefinitions(testcase);     while (defs.movenext())         {             testsetups testsetup = new testsetups(defs);             idefinitionlist valsetup = gdl.getdefinitions(testsetup);             {                 tabelactsca ctsca = new tabelactsca(valsetup);                 testsetup.valsetup.add(ctsca);             }             testcase.setups.add(testsetup);             }         return testcase; ... } 

i want put ctsca values in valsetup list. works fine, except line testcase.setups.add(testsetup);: have the properties of testsetups class valsetup property empty, when while goes iteration.

sorry weird explanation. i'm able explain in more detail.

update: in situation, store in each testsetup last valsetup value , not valsetup of each testsetup.

you've made m_valsetup static property, you're re-initializing every time create new instance of testsetups. if want shared list across instances of testsetups, use property initializer this:

private static list<tabelactsca> m_valsetup = new list<tabelactsca>(); 

and remove initialization of in constructor.

if didn't intend list shared, remove static keyword definition.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -