Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 937 posts 2572 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 144 posts 273 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 937 posts 2572 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 144 posts 273 karma points MVP c-trib
    Oct 15, 2014 @ 13:52
    Amalie Wowern
    0

    but you should be able to remove '@'

  • Claushingebjerg 937 posts 2572 karma points
    Oct 15, 2014 @ 13:56
    Claushingebjerg
    100

    Yup

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

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

    Works too

Please Sign in or register to post replies

Write your reply to:

Draft