[Mono-list] Newbie and ArrayList

Johannes Graumann johannes_graumann at web.de
Mon Apr 16 05:28:54 EDT 2007


Jonathan Pryor wrote:

> 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 };

This would have been my next question ... thanks for your insights.

Joh



More information about the Mono-list mailing list