hello all, this is posted for people trying to avoid the Microsoft.VisualBasic namespace. I have accidentally learned this from another problem in the C# forums.

The ReDim statement actually uses the Microsoft.VisualBasic namespace internally (which most people advise not to use at all), as shown by the following code:

VB Code:
  1. ReDim Preserve Tracks(Tracks.GetUpperBound(0) + 1)

this compiles into MSIL, then decompiling back into C# (with Fox decompiler, freeware, at www.ozzydotnet.com) gives the following code (assume this.Tracks is an array already defined):

Code:
this.Tracks = (MIDI.Track)Utils.CopyArray((Array)this.Tracks, new MIDI.Track[(this.Tracks.GetUpperBound(0) + 1) + 1]);
For those in VB this is
VB Code:
  1. ' ---- WITH CASTING ----
  2. Me.Tracks = CType([COLOR=Red]Utils[/COLOR].CopyArray(CType(Me.Tracks, Array), New MIDI.Track(Me.Tracks.GetUpperBound(0) + 1) {}), MIDI.Track())
  3. ' ---- WITHOUT CASTING : ----
  4. Me.Tracks = [COLOR=Red]Utils[/COLOR].CopyArray(Me.Tracks, New MIDI.Track(Me.Tracks.GetUpperBound(0) + 1) {})

Putting the mouse over 'Utils' gives Microsoft.VisualBasic.CompilerServices.Utils. Bottom line : every ReDim Preserve statement gives a call to the Microsoft.VisualBasic namespace (unless i overlooked something, it's been awhile since i used VB.NET, i work mainly in C# now). Please everybody tell me what you think of this!!