Results 1 to 4 of 4

Thread: ()?: Question

  1. #1

    Thread Starter
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

    Resolved ()?: Question

    Is there something wrong in my code?
    Code:
    (i%2==0)?li.BackColor=Color.White:li.BackColor=Color.OldLace;
    BTW, li is a ListViewItem. Thank you.

    edit: The error is "Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
    Last edited by brown monkey; Dec 9th, 2004 at 08:53 PM.

  2. #2
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Re: ()?: Question

    As far as I'm aware, it goes
    Code:
    (expression)?statement:statement;
    I don't think you can actually use expressions in place of the statements. It's just for returning values.

    Try
    Code:
    if ( i%2 == 0 )
    {
         li.BackColor = Color.White;
    }
    else
    {
         li.BackColor = Color.OldLace;
    }
    I'm pretty sure that will work.

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Re: ()?: Question

    Oh I just thought of something actually;
    Code:
    li.BackColor = (i%2 == 0)?Color.White:Color.OldLace;
    Try that

  4. #4

    Thread Starter
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

    Re: ()?: Question

    Quote Originally Posted by TomGibbons
    Oh I just thought of something actually;
    Code:
    li.BackColor = (i%2 == 0)?Color.White:Color.OldLace;
    Try that
    God. I'm totally lost. Thank you, Tommy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width