SgDotNet
Singapore Professional .NET User Group -For Cool Developers

array redim and redim preserve

rated by 0 users
This post has 5 Replies | 3 Followers

Top 500 Contributor
Posts 6
plsaiuser Posted: 01-17-2006 10:25 AM
 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

Top 10 Contributor
Posts 1,221
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
Top 10 Contributor
Posts 865

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"

Top 100 Contributor
Posts 18

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)
Top 25 Contributor
Posts 154
 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
Top 500 Contributor
Posts 6
Thanks for your info
Page 1 of 1 (6 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems