Ary Borenszweig wrote: > How would you do this? > > X x; > > if(someCondition) { > x = new SomeX(); > } else { > x = new SomeOtherX(); > }
One option is the "turn everything into an expression" route. This is what Nemerle (think a functional superset of C#) did, and it's just BEAUTIFULLY expressive. > X x = if( someCondition ) new SomeX(); else new SomeOtherX(); Failing that, there's always this (note: didn't do a syntax check on this :P): > X x = ({if(someCondition) > return new SomeX(); > else return new SomeOtherX();})(); Or something to that effect. -- Daniel