[Mono-devel-list] Static Struct Initialisers?

Martin Baulig martin at gnome.org
Wed Mar 12 04:30:42 EST 2003


Michael Adams - CPX Tetra <michaela at ComparexAfrica.co.za> writes:

> I'm trying to create an array of structs and initialise it.
> However, this code doesn't compile. 
> Any way to do this ?

Hi,

it's done like this:

===
using System;

public struct SPoint
{
  public int x,y;
  public SPoint (int x, int y) {
    this.x = x; this.y = y;
  }
};

public class CMain
{
  public static void Main()
  {
    SPoint[] List = new SPoint[] { new SPoint (1,2), new SPoint (3,4) };
  }
}
====

-- 
Martin Baulig
martin at gnome.org
martin at ximian.com



More information about the Mono-devel-list mailing list