C# declare variable into if statement -



C# declare variable into if statement -

i want using c# :

if (i == 0) { button = new button(); } else { textblock = new textblock(); } mainpage.children.add(a);

but error

error 1 name 'a' not exist in current context

any ideas ?

thank in advance !

you need mutual base of operations class both button , textblock derive from, , needs declared outside of if statement if it's accessed after if complete. control maybe?

control a; if (i == 0) { = new button(); } else { = new textblock(); } mainpage.children.add(a);

not knowing specific command toolkit you're using (wpf maybe?) can't advise further. i'd @ signature add clue - what's parameter declared as?

c# variables if-statement

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -