SgDotNet
Singapore Professional .NET User Group -For Cool Developers

array redim and redim preserve

Latest post 01-19-2006 10:01 AM by plsaiuser. 5 replies.
  • 01-17-2006 10:25 AM

    array redim and redim preserve

     Greetings All,

    The following is the vb.net code i need equilant C# code. can anybody pls help me to complete the following

    Dim vaResultSet

    If Not IsArray(vaResultSet) Then

    ReDim vaResultSet(0)

    Else

    ReDim Preserve vaResultSet(UBound(vaResultSet) + 1)

    End If


    Thanks in advance
    sai

  • 01-17-2006 1:11 PM In reply to

    Re: array redim and redim preserve

    It's pretty much difficult to convert this into C# code, but let me try and see how it goes.

     plsaiuser wrote:
     

    Dim vaResultSet

    I'm not too sure what you're doing here, but maybe it's something like this.

    Object vaResultSet = new Object();

     plsaiuser wrote:
     

    If Not IsArray(vaResultSet) Then

    This can be done using something like this.

    Type at = typeof(vaResultSet);
    if (!at.IsArray) {

     plsaiuser wrote:

    ReDim vaResultSet(0)

    This is somewhat interesting. ReDim resizes the object to an array of 0. It's pretty difficult to do this unless vaResultSet has been declared an array first. I would suggest that the 1st line when declaring vaResultSet be an array instead. Or assign it to another variable and return the array instead. So I would do something like this.

    Before the if-else statement, I'll declare an array variable first.

    Object[] myArray;

    Then for the ReDim itself,

    myArray = new Object[1];

    myArray[0] = vaResultSet;

     plsaiuser wrote:

    Else

    ReDim Preserve vaResultSet(UBound(vaResultSet) + 1)

    This is also pretty interesting to do. In C# you won't be able to resize the object, so you'll have to create another new object to do so.

    myObject = new Object(varResultSet.Length) + 1);
    Array.Copy(myObject, varResultSet, varResultSet.Length);

     plsaiuser wrote:

    End If



    that should do the trick. You can replace Object with any type u require. I'm just assuming here.
    Regards, triplez ------------------------------ http://triplez.mine.nu/blogs
  • 01-17-2006 9:47 PM In reply to

    Re: array redim and redim preserve

    Use this: http://www.carlosag.net/Tools/CodeTranslator/Default.aspx and you will get this:

    object vaResultSet;
    if (!IsArray(vaResultSet)) {
        object vaResultSet;
    }
    else {
        object Preserve;
        vaResultSet((UBound(vaResultSet) + 1));
    }

    ~Softwaremaker (BLOG) M. Twain: "I didn't have time to write a short letter, so I wrote a long one instead"
  • 01-19-2006 12:36 AM In reply to

    Re: array redim and redim preserve

    Hi plsaiuser,

    Even though it is not equivalent(identical) translation, it will be better if you can rewrite the coding by using ArrayList.

     

    (0__0)let's rock & get rocked(0__0)
  • 01-19-2006 9:56 AM In reply to

    Re: array redim and redim preserve

     Softwaremaker wrote:

    Use this: http://www.carlosag.net/Tools/CodeTranslator/Default.aspx and you will get this:

    object vaResultSet;
    if (!IsArray(vaResultSet)) {
        object vaResultSet;
    }
    else {
        object Preserve;
        vaResultSet((UBound(vaResultSet) + 1));
    }



    the conversion is wrong, isn't it?
    http://feelite.com/blog
  • 01-19-2006 10:01 AM In reply to

    Re: array redim and redim preserve

    Thanks for your info
Page 1 of 1 (6 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems