Skip to content

Array problem

Kelvin Loke

Asked Jun 1, 2007, 5:38 AM EDT1 answer
Share
LinkedInX
Hi,I´m new with C# and I need to create a global array, but I´m doing something wrong.. This is how I create the global array.. public class MyClass { int i = 0; int[] vrgb = new int[3000]; public static int[] RGB { get { return vrgb[i]; } set { vrgb[i] = value; } } } This is how I call it: int i; i = Program.Indice; int[] contenedor; contenedor = RGBvector.MyClass.RGB; contenedor[i] = ValorRojo; RGBvector.MyClass.RGB = contenedor[i]; note that Valor rojo = int. can anyone help me? the errors I get are: 1.cannot implicitly covert int to int[] 2.Error 4 An object reference is required for the nonstatic field, method, or property 'RGBvector.MyClass.vrgb' Thank you very much.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    Hi,I´m new with C# and I need to create a global array, but I´m doing something wrong.. This is how I create the global array..

    public class MyClass
     {
       int i = 0; int[] vrgb = new int[3000];
       public static int[] RGB
        {
          get { return vrgb[i]; }
          set { vrgb[i] = value; }
        } 
    }
     
    int i;
    i = Program.Indice;
    int[] contenedor;
    contenedor = RGBvector.MyClass.RGB;
    contenedor[i] = ValorRojo;
    RGBvector.MyClass.RGB = contenedor[i];

    the errors I get are:
     1.cannot implicitly covert int to int[]
     2.Error 4 An object reference is required for the nonstatic field, method, or property 'RGBvector.MyClass.vrgb' Thank you very much.

    ---
    1.  Your property is returning an integer inside the array (int), but you declared your property
         to return an array (int[])

    Your property should be:
       static int[] vrgb = new int[3000]; 

       public static int[] RGB
        {
          get { return vrgb; }
          set { vrgb = value; }
        } 

    2.  You can't have a static property using a non-static private member.
    vrgb also needs to be static.

    static int[] vrgb = new int[3000]; 
    0