Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have a string array in which there are max of 4 strings


C#
string[] userInput = new string[4];


I need to eliminate first element of the array and assign the remaining elements to another string array like below
C#
GWmsgDetails.GatewayBuses = userInput;
br mode="hold" />Can anyone please tell me, how can I wrote code for this


Thanks
John
Posted
Updated 13-Mar-14 5:24am
v3

Try:
C#
string[] userInput = new string[] { "hello", "there", "world"};
string[] withFirstBitMissing = new string[userInput.Length - 1];
Array.Copy(userInput, 1, withFirstBitMissing, 0, withFirstBitMissing.Length);  
 
Share this answer
 
another solution by using linq:

C#
string[] arr1 = new string[4] { "1", "2", "3", "4" };
string[] arr2 = arr1.Skip(1).ToArray();
 
Share this answer
 
Solution by for loop

string[] userInput = new string[4] {"1","2","3","4"};
string[] userOutput = new string[userInput.Length -1 ];

for (int i = 1, j = 0 ; i < userInput.Length; i++ , j++)
userOutput[j] = userInput[i];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900