Thread: C# Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0

    C# Help


    I've been coding a bit and am wondering if anybody will be able to help with these code issues (I'm usung C# and XNA 4.0 Refresh)
    Code:
    List<Button> buttons = new List<Button>();
    
    for (int i = 0; i < buttons.Count; i++)
                {
                    buttons(i).Update();
    
                    if (buttons(i).clicked)
                        buttons(i).Effect();
                }
    
    {
    for (int i = 0; i < buttons.Count; i++)
                    buttons(i).Draw;
    }
    The four errors that result from this all say "buttons is a field but is used like a type"
    Another snag I've come across
    Code:
    layer = new int(mapWidth, mapHeight);
    The error from this says "int does not contain a constructor that takes 2 arguments"

    Any help would be greatly appreciated
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    I think in the first error instead of saying buttons(i), you want to call the method on a list that retrieves that element.

    For the second error, what are you trying to do?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    Originally Posted by bullet
    I think in the first error instead of saying buttons(i), you want to call the method on a list that retrieves that element.

    For the second error, what are you trying to do?
    On a list that retrieves that element, what exactly do you mean by that? What code could I use? For the second error, I'm trying to retrieve the size of layer.
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Problematic
    On a list that retrieves that element, what exactly do you mean by that? What code could I use? For the second error, I'm trying to retrieve the size of layer.
    What I mean on the first error is that there is probably a method in List that lets you retrieve the element at position i.

    Why are you trying to create an int? What should the value be?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    I've been learning this from a C# 2008 tutorial and an int was created for that reason, I know that C# 2008 and 2010 aren't exactly the same but I don't know how to fix that error (I managed to fix the buttons(i) errors by replacing with foreach loops)

IMN logo majestic logo threadwatch logo seochat tools logo