VB6.0 to newbie C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Harrington

    #1

    VB6.0 to newbie C#

    Is there a C# equivalent to Vb6's Erase when dealing with arrays?
    Also vb6 handles the long variable type better (speedwise) than int.
    Is this also the case in C#?
    TIA Mick.


  • Alberto Poblacion

    #2
    Re: VB6.0 to newbie C#

    "Michael Harrington" <mikharr@bigpon d.comwrote in message
    news:e4t4juJwIH A.4952@TK2MSFTN GP05.phx.gbl...
    Is there a C# equivalent to Vb6's Erase when dealing with arrays?
    If I remember correctly, VB6 Erase removed all elements of an array and
    left the array with length zero. In C#, you could achieve a similar effect
    by assigning a new array with zero elements:

    string[] theArray = ...;
    ....
    theArray = new string[0];

    Or, if you don't need to use it as a referece, just set it to null:

    theArray = null;
    Also vb6 handles the long variable type better (speedwise) than int.
    Is this also the case in C#?
    In C# the int type is 32-bits wide, therefore it is equivalent to the
    Long type in VB6. The old Integer in VB6 (16-bits) would be a "short" in C#.

    Comment

    • Peter Duniho

      #3
      Re: VB6.0 to newbie C#

      On Wed, 28 May 2008 01:30:02 -0700, Alberto Poblacion
      <earthling-quitaestoparaco ntestar@poblaci on.orgwrote:
      "Michael Harrington" <mikharr@bigpon d.comwrote in message
      news:e4t4juJwIH A.4952@TK2MSFTN GP05.phx.gbl...
      >Is there a C# equivalent to Vb6's Erase when dealing with arrays?
      >
      If I remember correctly, VB6 Erase removed all elements of an array
      and left the array with length zero.
      Looking at the docs, it appears to me that Erase simply removes the array
      altogether, leaving the identifier unusable until the array is "ReDim"'ed.

      In that respect, I think assigning the array to null is closer to the
      actual idea the OP has.

      However: according to the docs, Erase is strictly a procedure-level
      thing. It can only be used on local variables. In C#, assigning a local
      variable to null is pointless. The compiler already can tell whether a
      local variable is used past some point within the method body, and makes
      the object a variable references eligible for garbage collection if that
      variable isn't used again within the method. All that assigning to null
      does is extend the lifetime of that object to the point where the variable
      was assigned to null.

      In other words, the correct answer to the OP is very likely: the best
      "equivalent " in C# to the Erase statement is to do nothing at all.

      Pete

      Comment

      Working...