Conditional Assignment

  • Thread starter Thread starter Fir5tSight
  • Start date Start date
F

Fir5tSight

Hi All,

I have the following code in C#:

lSelectedFilter = 1;
this.tabFilters.SelectedIndex = (lSelectedFilter == 0 ? 0
: lSelectedFilter - 1);

After executing the above statements, this.tabFilters.SelectedIndex is
changed to -1. Why? I expected it to be 0. Anyone can explain it to me?

Thanks!

-Emily
 
Fir5tSight said:
I have the following code in C#:

lSelectedFilter = 1;
this.tabFilters.SelectedIndex = (lSelectedFilter == 0 ? 0
: lSelectedFilter - 1);

After executing the above statements, this.tabFilters.SelectedIndex is
changed to -1. Why? I expected it to be 0. Anyone can explain it to me?

You should work out whether the problem is with the value you're trying
to assign to SelectedIndex, or the SelectedIndex property itself.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Back
Top