We have an array in which we have some elements
we wish that user insert a value at a specified position in the array....
how is this done
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 28, 2014, 12:57 AM EST
The output is:
a b c d e f
As the others have said, if you intend to do a lot of insertions, you're best using a List
Abhay ShankerRank #375 · 6.7K reputationPosted Feb 27, 2014, 6:48 PM EST
http://stackoverflow.com/questions/9570944/adding-elements-to-a-c-sharp-array
But why are you not using arraylist
Abhijit PatilRank #700 · 3.4K reputationPosted Feb 27, 2014, 10:01 PM EST
you can use arraylist
Indices are zero based. So the first item is at index 0 and the tenth item at index 9
ArrayList.Insert
C# int posNum; if(!int.TryParse(txtPosition.Text, out posNum)) { // show message return; } else if(posNum 0 || posNum > ActorArrayList.Count) { // show message return; } ActorArrayList.Insert(posNum, actName); } If you want to add the object at the end anyway, you just have to use Add: ActorArrayList.Add(actName); hope it helpsVulpesRank #55 · 29.2K reputationPosted Feb 28, 2014, 1:07 AM EST