2
Reply

How to do this in C# (dynamic resize)

Marc

Marc

May 28 2008 6:18 AM
7.4k
I have to convert this code in VB.Net in C#

reDim vars(0).VarValue(3)
vars(0).VarValue(0) = New Object
vars(0).VarValue(1) = New Object
vars(0).VarValue(2) = New Object

where varvalue is type Object, in C# I haven't found any method to resize dynamic like redim VarValue that is type Object to Object[3].

Another alternative in VB.net to do this is

vars(0).VarValue = New Object() {CObj("qwer"), CObj("asdf")}


but I haven't found how to do in C#

I have try in C#

vars[0].VarValue = new Object()[3];

But evidently the type of object insn't resized to Object[3], an when i try to access
Vars[0].VarValue[0] = "asdf"
I get the error "Error    Cannot apply indexing with [] to an expression of type 'object' "

Anybody knows how to do this in C# ?

I believe that the problem is C# can't do dynamics resize.

Thanks for your help in advance

Answers (2)