473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Equivalent of Redim

san
Hello

Wht is equivalent of Redim(VB) in C#.

Thanks in Advance
Nov 15 '05 #1
5 1774
See this newsgroup thread:
http://groups.google.com/groups?hl=e...sftngp04#link1

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

"san" <fe*********@hotmail.com> kirjoitti viestissä
news:e%****************@TK2MSFTNGP12.phx.gbl...
Hello

Wht is equivalent of Redim(VB) in C#.

Thanks in Advance

Nov 15 '05 #2
san <fe*********@hotmail.com> wrote:
Wht is equivalent of Redim(VB) in C#.


Create a new array of the right size, use Array.Copy to copy to give
the new array the same contents (where appropriate) as the old array,
and then discard the old array, using the new one instead.

Alternatively, use ArrayList from the start, where appropriate.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3
I frequently use ArrayList internally, then copy to a strongly typed array
before returning.

private string[] DeDup(string[] Source)
{
ArrayList ret = new ArrayList();
string[] dest = null;

for (int i = 0; i < Source.Length; i++)
{
if (!ret.Contains(Source[i])) //prevent duplicate entries
ret.Add(Source[i]);
}

if (ret.Count > 0)
{
dest = new string[ret.Count];
ret.CopyTo(dest);
}

return dest;
}

HTH,
Eric Cadwell
http://www.origincontrols.com

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
san <fe*********@hotmail.com> wrote:
Wht is equivalent of Redim(VB) in C#.


Create a new array of the right size, use Array.Copy to copy to give
the new array the same contents (where appropriate) as the old array,
and then discard the old array, using the new one instead.

Alternatively, use ArrayList from the start, where appropriate.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #4
If you are doing this frequently, why then don't you use a strongly typed
collection instead?
This way, you have the convenience of ArrayList without the penalty of the
Copy at the end.
Just find a strongly typed collection generator (there are many) and point
it at your type (in this case, string)
Just a thought,

Oscar.

"Eric Cadwell" <ec******@no.insight.spam.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
I frequently use ArrayList internally, then copy to a strongly typed array
before returning.

Nov 15 '05 #5
Eric Cadwell <ec******@no.insight.spam.com> wrote:
I frequently use ArrayList internally, then copy to a strongly typed array
before returning.


<snip>

Rather than do the copying manually, you can use
ArrayList.ToArray(typeof(string)) instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Trevor Fairchild | last post by:
I've got a program that parses text files. The text files come to me in Unicode and they contain goofy characters that VB chokes on - treats them as eof markers. I have already been through this...
2
by: Wayne Wengert | last post by:
I am trying to add one column to an existing array (code below). The ReDim command gives the error: ----------------------------------------------- Microsoft VBScript runtime error '800a0009' ...
2
by: | last post by:
Is it correct to think that after reducing the populated array's size from say, 10 to 5 with redim preserve myArray(i) an attempt to access an element above the fifth does not cause a...
6
by: John Grandy | last post by:
Does C# have an equivalent for VB.NET's Redim Preserve ? ReDim Preserve increases the final dimension of any array while preserving the array's contents (however, the type of the array may not be...
4
by: Daryl Davis | last post by:
I am having trouble with ReDim (see code below) SaleTable2's structure includes an array for SaleDetailTable2 Dim newsale As New hallsales.SaleTable2 Dim detail As New hallsales.SaleDetailTable2...
5
by: Zenobia | last post by:
Hello, I want to keep a list references to database records being accessed. I will do this by storing the record keys in a list. The list must not contain duplicate keys. So I check the...
9
by: John A Grandy | last post by:
In VB6 you could get away with the following code: Dim Index As Integer Dim ItemsCount As Integer Dim StringArray() As String Dim StringValue As String '....
5
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.