I would like to move the values of an array up one in the index.
This is what i tried but it didn't work.
int[] intArr = new int[5];
Array.Copy(intArr, 0, intArr 1, 4);
intArr[0] = userinput;
//this is how it should work
userinput: 5
intArr {5,null,null,null,null}
userinput: 4
intArr {4,5,null,null,null}
userinput: 9090
intArr {9090,4,5,null,null}
////
Thanks in advance 2 3388
Not sure what you mean, but the following program appears to work:
using System;
public class ShiftArray {
private static void Main() {
int[] foo = new int[5];
int count = 9;
while(count > 0) {
foo[0] = count--;
DumpContents(foo);
Array.Copy(foo, 0, foo, 1, 4);
}
}
private static void DumpContents(int[] array) {
for(int i = 0; i < array.Length; i++) {
Console.Write(array[i]);
}
Console.WriteLine();
}
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Aaron" <ku*****@yahoo.com> wrote in message
news:b4*************************@posting.google.co m... I would like to move the values of an array up one in the index. This is what i tried but it didn't work.
int[] intArr = new int[5]; Array.Copy(intArr, 0, intArr 1, 4); intArr[0] = userinput;
//this is how it should work userinput: 5 intArr {5,null,null,null,null}
userinput: 4 intArr {4,5,null,null,null}
userinput: 9090 intArr {9090,4,5,null,null} ////
Thanks in advance
Aaron wrote: //this is how it should work userinput: 5 intArr {5,null,null,null,null}
userinput: 4 intArr {4,5,null,null,null}
userinput: 9090 intArr {9090,4,5,null,null} ////
Have a look at System.Collections.Stack.
--
Gravity: it's not just a good idea, it's the law. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex Vinokur |
last post by:
==========================================
Windows 2000 Professional
CYGWIN_NT-5.0 1.5.4(0.94/3/2)
GNU g++ version 3.2 20020927 (prerelease)
GNU objdump 2.14.90 20030901...
|
by: someone |
last post by:
On page 106 of the second edition of "The C Programming Language" by K
& G, two stack operations PUSH n POP are given.
>> PUSH
*p++ = val;
>>POP
val = *--p;
What I know about stacks is...
|
by: Mel |
last post by:
i have an text field and a button
when user click on button it popups up list of emails in a form
user selects a bunch of people from the form (check boxes) and when the
window is closed the...
|
by: someone |
last post by:
On page 106 of the second edition of "The C Programming Language" by K
& G, two stack operations PUSH n POP are given.
>> PUSH
*p++ = val;
>>POP
val = *--p;
What I know about stacks is...
|
by: G Patel |
last post by:
Can people please comment on the layout/style of my problem? The major
issue I had was the layout. I ended up having to put a relatively
large switch statement, inside an if statement, which is...
|
by: Aaron |
last post by:
I would like to move the values of an array up one in the index.
This is what i tried but it didn't work.
int intArr = new int;
Array.Copy(intArr, 0, intArr 1, 4);
intArr = userinput;
...
|
by: alisaee |
last post by:
plz check what i have made wrong what is requierd her is to creat class
queue and class stack and run the push,pop operation .
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class...
|
by: Bryan Parkoff |
last post by:
Do you know that current C++ Compiler limits to 64KB segments in source
code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB
segments in source code. 4GB segment is ideal for...
|
by: mdh |
last post by:
I wonder if I could ask for help. I have been struggling with this
most of the day, and cannot understand what is going on. The problems
are (1) it does not work!! (but exits normally on...
|
by: matth |
last post by:
I've been working on something that deals with handling a user's
selection within the DOM and I'm tripping up on one last, but crucial,
detail.
Forgive me for the length of the code, but my...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |