Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 939 posts 2574 karma points
    Oct 15, 2014 @ 13:43
    Claushingebjerg
    0

    changing variable if condition is met.

    var cols = 12/@boxList.Count();
    
    if (@cols < 3) {
        cols = 3;
    }
    
    Can anybody tell me why this doesnt work?
    The original var works fine. When i add the condition i get the following error:

    Compiler Error Message: CS1026: ) expected
  • Amalie Wowern 145 posts 274 karma points MVP c-trib
    Oct 15, 2014 @ 13:48
    Amalie Wowern
    0

    try

    var cols = 12/boxList.Count();
    
    if (cols < 3) {
        cols = 3;
    }
    
  • Claushingebjerg 939 posts 2574 karma points
    Oct 15, 2014 @ 13:50
    Claushingebjerg
    0

    Found it. The var had to be encased in paranthises...

    var cols = (12/@boxList.Count());

    if(@cols<3){
        cols =3;
    }
  • Amalie Wowern 145 posts 274 karma points MVP c-trib
    Oct 15, 2014 @ 13:52
    Amalie Wowern
    0

    but you should be able to remove '@'

  • Claushingebjerg 939 posts 2574 karma points
    Oct 15, 2014 @ 13:56
    Claushingebjerg
    100

    Yup

    var cols =(12/@boxList.Count());

    if(cols<3){
        cols = 3;
    }

    Works too

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies