Thread: struct problem

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    struct problem

    I created one struct type:

    struct Point
    {
    public int x,
    public int y,
    }

    and no problem for creating one reference:

    Point mypoint = new Point();

    but if I create a array like:
    Point mypoint[3] = new Point();

    Then this is wrong, so what is the right way then?
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    The following is a paragraph from the help topic "arrays". The help is the first thing you should turn to for advice.

    Arrays in General
    C# arrays are zero indexed; that is, the array indexes start at zero. Arrays in C# work similarly to how arrays work in most other popular languages There are, however, a few differences that you should be aware of.

    When declaring an array, the square brackets ([]) must come after the type, not the identifier. Placing the brackets after the identifier is not legal syntax in C#.

    int[] table; // not int table[];
    Another detail is that the size of the array is not part of its type as it is in the C language. This allows you to declare an array and assign any array of int objects to it, regardless of the array's length.

    int[] numbers; // declare numbers as an int array of any size
    numbers = new int[10]; // numbers is a 10-element array
    numbers = new int[20]; // now it's a 20-element array

    ---

    So for your example:

    Point [] points = new Point[37];

    You should note that Point already exists in the Drawing namespace, so if you need Points, it might be best to use those that already exist, or name your's differently.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    HAHA, thanx
    Don't laugh at me,I am just a SuperNewbie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct File and array problem Please help
    By theprogrammer in forum C Programming
    Replies: 17
    Last Post: 04-02-2009, 08:05 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  4. Replies: 22
    Last Post: 12-23-2008, 01:53 PM
  5. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM