[Mono-list] Newbie and ArrayList

Jonathan Pryor jonpryor at vt.edu
Mon Apr 16 05:10:09 EDT 2007

On Mon, 2007-04-16 at 00:40 -0500, Jonathan Gilbert wrote:
> At 10:13 PM 4/15/2007 +0200, Johannes Graumann wrote:
> [snip]
> >  [TestFixture()]
> >  public class Test
> >  {
> >    #region Establishment of Testing Infrastructure
> [snip]
> >    // Construct the names needed for the mock directory structure
> >    ArrayList DSYears = new ArrayList();
> >    DSYears.Add(1);
> [snip]
> Just to give a bit more detail, basically (and I hope it's not too much
> detail -- I'm a compulsive over-explainer), it looks like what you're
> aiming for is to have the "DSYears" ArrayList start off with one value in
> it as soon as the instance is created (i.e., at the same time that
> "DSYears" is assigned its "new ArrayList()" value). Unfortunately,
> *statements* must be inside the bodies of methods or accessors (properties
> and events). The initializers within a class may consist only of
> expressions that can be evaluated before the instance of the class has been
> initialized.

Which is why C# 3.0 Collection Initializers will be useful: we can
initialize DSYears with a collection initialization expression, thus
keeping everything in one expression instead of multiple statements:

	ArrayList DSYears = new ArrayList () { 1 };

Of course, C# 3.0 hasn't been finalized, and it doesn't exist in mcs
proper yet either (a potential patch is attached to bugzilla 81356).

 - Jon

More information about the Mono-list mailing list