1

I'm newbie in C#. Perhaps this is too simply to resolve but I'm really away of the solution.

I have this class:

public class TestSetups : TabelaCtset { public IList<TabelaCtsca> ValSetup { get { return m_valsetup; } } private static List<TabelaCtsca> m_valsetup; /// Constructor public TestSetups(IDefinitionList dlist) : base(dlist) { m_valsetup = new List<TabelaCtsca>(); } } 

I have another class called TestCase

public class TestCase : TabelaCttes { public IList<TestSetups> Setups { get { 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 to put all ctsca values in a ValSetup list. All works fine, except this line testcase.Setups.Add(testsetup);: I have the the properties of TestSetups class but my ValSetup property is always empty, when my while goes to another iteration.

Sorry for this weird explanation. I'm able to explain in more detail.

Update: In this situation, I store in each TestSetup just the last ValSetup value and not all the ValSetup of each TestSetup.

1
  • Can you show the rest of the function? And where it's called from. Commented Apr 14, 2015 at 17:13

1 Answer 1

3

You've made m_valsetup a static property, but you're re-initializing every time you create a new instance of TestSetups. If you want it to be a shared list across all instances of TestSetups, then you could use a property initializer like this:

private static List<TabelaCtsca> m_valsetup = new List<TabelaCtsca>(); 

And remove the initialization of it in the constructor.

If you didn't intend for the list to be shared, then just remove the static keyword from its definition.

Sign up to request clarification or add additional context in comments.

2 Comments

I want a TestCase with a list of TestSetups who have a list of ValSetups. With your solution I have all the ValSetups in all TestSetups.
I made it! Thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.