If the code you provided is the complete code, it won't. Never. You see, you've declared members
bool Nokia5233;
bool Nokia2690;
bool SonyP910i;
but you dont' set their values. So, they retain thair default values, which are
false
. So no
if
is gonna trigger in
ListOfMobiles()
. And
Price
value is never set as well - so what do you expect?
What you need here is to set corresponding boolean value (e.g.
Nokia2690
) in
ChooseMobile()
method depending on user input. Use
switch
for that. One more - and probably better - option is to turn your
MobileName
into property with switch in its set part that would tune your object (set corresponding bool value and price).
That'll help your solution work, no more. There are certanly other improvements that can be done, for example removing bool variables completely or replacing them by enum member