Hi,
I have an array with 2 elements and I would like to keep
the elements but redimension the array so that I can add
another value.
How do I do this.
I have tried this but, i think I have screwy logic.
Thanks
intRedimArray = arr_Selected.Le ngth;
object tmp_arr = arr_Selected.Cl one();
arr_Selected (string [])tmp_arr;
arr_Selected = new string[intRedimArray];
arr_Selected[intArrayCounter-1] = strToAdd;
tmp_arr= null;
the program will keep showing 1.
MessageBox.Show (arr_Selected.L ength.ToString( ));
Thanks for your help,
y 5 8364
You might be better off using an ArrayList.
"y" <y@hotmail.co m> wrote in message
news:09******** *************** *****@phx.gbl.. . Hi,
I have an array with 2 elements and I would like to keep the elements but redimension the array so that I can add another value.
How do I do this.
I have tried this but, i think I have screwy logic.
Thanks
intRedimArray = arr_Selected.Le ngth; object tmp_arr = arr_Selected.Cl one(); arr_Selected (string [])tmp_arr; arr_Selected = new string[intRedimArray];
arr_Selected[intArrayCounter-1] = strToAdd; tmp_arr= null;
the program will keep showing 1. MessageBox.Show (arr_Selected.L ength.ToString( ));
Thanks for your help,
y
"y" <y@hotmail.co m> wrote in message
news:09******** *************** *****@phx.gbl.. . intRedimArray = arr_Selected.Le ngth; object tmp_arr = arr_Selected.Cl one(); arr_Selected (string [])tmp_arr; arr_Selected = new string[intRedimArray];
arr_Selected[intArrayCounter-1] = strToAdd; tmp_arr= null;
the program will keep showing 1. MessageBox.Show (arr_Selected.L ength.ToString( ));
This won't work because the array size for 'new string[intRedimArray]'
should be a compile time constant. You can use Array.CreateIns tance instead.
y,
To redimension an array you need to create a new array, copy the existing
elements to the new array, start using the new array.
Something like:
string[] list;
int newLength = list.Length + 5;
string[] temp = new string[newLength];
list.CopyTo(tem p, 0);
list = temp;
Note, if you are decreasing the size of the array, you can use Array.Copy
instead of CopyTo.
Array.Copy(list , 0, temp, 0, newLength);
Actually Array.Copy works for either increasing or decreasing the array. As
long as you don't try to copy more elements than what is in the source array
or the destination array.
Hope this helps
Jay
"y" <y@hotmail.co m> wrote in message
news:09******** *************** *****@phx.gbl.. . Hi,
I have an array with 2 elements and I would like to keep the elements but redimension the array so that I can add another value.
How do I do this.
I have tried this but, i think I have screwy logic.
Thanks
intRedimArray = arr_Selected.Le ngth; object tmp_arr = arr_Selected.Cl one(); arr_Selected (string [])tmp_arr; arr_Selected = new string[intRedimArray];
arr_Selected[intArrayCounter-1] = strToAdd; tmp_arr= null;
the program will keep showing 1. MessageBox.Show (arr_Selected.L ength.ToString( ));
Thanks for your help,
y This won't work because the array size for 'new string[intRedimArray]' should be a compile time constant.
I'm affraid this statement is not quite correct....
"Val Savvateev" <1@2.com> wrote in message
news:ut******** *******@TK2MSFT NGP10.phx.gbl.. . This won't work because the array size for 'new string[intRedimArray]' should be a compile time constant.
I'm affraid this statement is not quite correct....
I'm affraid you're right... my C++ background is showing :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brian |
last post by:
I'm diddlying with a script, and found some behavior I don't understand.
Take this snippet:
for ($i = 0; $i <= count($m); $i++) {
array_shift($m);
reset($m);
}
|
by: Stormkid |
last post by:
Hi Group I'm trying to figure out a way that I can take two (two
dimensional) arrays and avShed and shed, and subtract the matching elements
in shed from avShed I've pasted the arrays blow from a print_r cmd any
suggestions would be great. Thanks much Todd
//avShed array
Array ( => Array ( => 1 => 08:00 ) => Array
( => 1 => 08:05 ) => Array ( => 1
=> 08:10 ) => Array ( => 1 => 08:15 )
=> Array ( => 1 => 08:20 ) => Array...
|
by: lawrence |
last post by:
I wanted to test xml_parse_into_struct() so I took the example off of
www.php.net and put this code up on a site:
<?php
$simple = <<<END
<item>
|
by: vcardillo |
last post by:
Hello all,
Okay, I am having some troubles. What I am doing here is dealing with
an employee hierarchy that is stored in an array. It looks like this:
$employees = array( "user_id" => array( "name", "title",
"reports to user id", "start date in the format: mm/dd/yyyy" )
);
How can I display this hierarchy in simple nested <li> tags in the most
|
by: Sam Collett |
last post by:
How do I remove an item with a specified value from an array?
i.e. array values 1,2,2,5,7,12,15,21
remove 2 from array would return
1,5,7,12,15,21
(12 and 21 are NOT removed, duplicates are also removed)
So far I have (val is value, ar is array, returns new array):
| |
by: Mike S. Nowostawsky |
last post by:
I tried using the "toUpperCase()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?
Ex:
var GridArrayName1 = new Array();
GridArrayName1 = new Array ('test-value');
GridArrayName1 = GridArrayName1...
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of code...
TCHAR myArray;
DoStuff(myArray);
|
by: Kurt Lange |
last post by:
HI,
how to redimension an array in c#, and preserve it's
contents (without using arraylist).
In visual basic it...
Dim I_interfaceArray() as I_interface = new I_interface()
{objInterface}
Redim Preserve I_interfaceArray(2)
|
by: Logan |
last post by:
Greetings to all, i need to create a matrix (or something that make the job)
to store 3 values per row to insert everything (there will be several rows)
later in my database but i can´t find a way to do it, any help can be usefull.
Thank you in advance.
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |