Hello everyone, is there a way to simulate VBs redim function in C#


Re: Visual C# Language Redim in C#


Check Array.Resize

Re: Visual C# Language Redim in C#


Thank you sir

Re: Visual C# Language Redim in C#


Redim is used to resize some array, so while working in .Net or specifically C# i would recomend you using Collections under System.Collecitons.Generics namespace.

like List<T> class

Dictionary<T,S> class etc


List<int> list = new List<int>(); // create a colleciton to store int....

list.Add(1); // Add some number

list.Add(2); // Add another Number.

This will automatically be resized whenever you add something to it and you don't need Redim anymore here.

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp

Re: Visual C# Language Redim in C#


public static Array Redim(Array origArray, Int32 desiredSize)
System.Type t = origArray.GetType().GetElementType();
Array newArray = Array.CreateInstance(t, desiredSize);
Array.Copy(origArray, 0, newArray, 0, Math.Min(origArray.Length, desiredSize));
return newArray;

//from Applied Microsoft.NET framework Programming - Jeffrey Richter

Re: Visual C# Language Redim in C#

Matthew Watson

Bear in mind that that's obsolete (only needed for .Net 1.x).

For .Net 2.x and later, use Array.Resize<T>() as stated previously.