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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top