473,808 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

redim arrayx?????


As you might have guessed,
I am trying to switch from
vb to c#, but I am having
a little difficulty.

How would you resize an array in
c# ? Is there a "redim preserve"
as well??

An example would go a long way.
Thanks jamie
Nov 17 '05 #1
4 1433
You have to do it yourself, manually. You have to create a new array
and copy the elements into it:

int[] myArray = new int[5];
int[] temp = new int[10];
for (int i = 0; i < myArray.Length; i++)
{
temp[i] = myArray[i];
}
myArray = temp;

That's why it's much more common in C# to use ArrayList and convert to
an array only when you really need an array (for example to pass to
some method that requires an array).

Nov 17 '05 #2
Use an ArrayList. It will resize itself as you need it to. Internally, it
creates a copy of the array with the new size, and copies the existing data
to the copy, then renames the copy - which is exactly what a redim preserve
in VB does internally.

HTH

Dale Preston
MCAD, MCDBA, MCSE

"jamie" <an*******@disc ussions.microso ft.com> wrote in message
news:14******** *************** *****@phx.gbl.. .

As you might have guessed,
I am trying to switch from
vb to c#, but I am having
a little difficulty.

How would you resize an array in
c# ? Is there a "redim preserve"
as well??

An example would go a long way.
Thanks jamie

Nov 17 '05 #3
Hum.....
I think I will have to do a little research on
the ArrayList.
Thanks.
-----Original Message-----
Use an ArrayList. It will resize itself as you need it to. Internally, itcreates a copy of the array with the new size, and copies the existing datato the copy, then renames the copy - which is exactly what a redim preservein VB does internally.

HTH

Dale Preston
MCAD, MCDBA, MCSE

"jamie" <an*******@disc ussions.microso ft.com> wrote in messagenews:14******* *************** ******@phx.gbl. ..

As you might have guessed,
I am trying to switch from
vb to c#, but I am having
a little difficulty.

How would you resize an array in
c# ? Is there a "redim preserve"
as well??

An example would go a long way.
Thanks jamie

.

Nov 17 '05 #4
I think the recipe is exactly
what I need to do. I knew I could
do it that way, I was just hoping
that I wouldnt have to for clarity
sake.

Thanks.
-----Original Message-----
You have to do it yourself, manually. You have to create a new arrayand copy the elements into it:

int[] myArray = new int[5];
int[] temp = new int[10];
for (int i = 0; i < myArray.Length; i++)
{
temp[i] = myArray[i];
}
myArray = temp;

That's why it's much more common in C# to use ArrayList and convert toan array only when you really need an array (for example to pass tosome method that requires an array).

.

Nov 17 '05 #5

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

Similar topics

4
7984
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 issue in another thread and I have received an answer that works (code is below) However, my test data thus far has been in the 10-50MB size range. I now have a case where the text file is 650MB in size! I need to convert it to ANSI for my...
2
15892
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' Subscript out of range /ListCGShowsGrouped.asp, line 58 ------------------------------------------------
9
5705
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 '....
19
3159
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 than in .Net environment, under VS 2005 Beta 2. Does anyone have any idea whether this will be addressed in the final release? Thanks, Tomasz
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.