c# scope/typing/assignment question
- by Shannow
Hi there another quick question.
I would like to create a variable object so that depending on the value of something, it gets cast as needed. e.g.
var rule;
switch (seqRuleObj.RuleType) {
case SeqRuleObj.type.Pre :
rule = new preConditionRuleType();
rule = (preConditionRuleType)seqRuleObj.Rule;
break;
case SeqRuleObj.type.Post :
rule = new postConditionRuleType();
rule = (postConditionRuleType)seqRuleObj.Rule;
break;
case SeqRuleObj.type.Exit :
rule = new exitConditionRuleType();
rule = (exitConditionRuleType)seqRuleObj.Rule;
break;
default :
break;
}
String result;
foreach (sequencingRuleTypeRuleConditionsRuleCondition cond in rule.ruleConditions.ruleCondition) {
....../ blah
}
so basically this will not work. c# will not allow me to create an new object in every case as the name is aleady defined.
i can just paste the foreach loop into each case but that to me is such a waste, as the objects are exactly the same in all but name.