i've searched forum similar issues , understand, global variables avoided. me not logical yet, i'm new programming. if i've understood correctly, static variable should job i'm looking for.
i've made combobox of 4 choices in mainwindow , when comboboxitem selected, variable b declared. done in private void selectionchanged.
when comboboxitem declaring variable b selected, usercontrol pops up. want use variable b further in program, can't access it. i've tried declare static int b;
in beginning of code, i'm not sure if understand use of static variable correctly. can please me?
avoid global variables , static
keyword @ unless 100% sure there no other address solution (sometimes might forced use statics typically legacy code hot fixes).
- statics/globals make tight code coupling
- breaks ood principles (typically dependency injection, single responsibility principles)
- not straightforward type initialization process many think
- sometimes makes not possible cover code unit test or break atrip principles tests (isolated principle)
so suggestion:
- understand problem in first place, roots, going achieve
- review design
Comments
Post a Comment