1

I have to add two int[] array in which a mian int[] array is intially vacant. I want to add the elements of another array in the main array . In the Main array, there would be more addtion that would be added in the last postion of the main array.

I have an array as -

var planetNotInRange = new int[7] ;

if(planetSign.Contains(tempFrind))
{
    var result = planetSign.Select((b, k) => b.Equals(tempFrind) ? k : -1)
                           .Where(k => k != -1).ToArray();

    // Here I want to add this result Array in to the planetNotInRange array, 
    // when ever there is some value in the result array.
}

this is in loop will give a number of array of integers. Now I want to concat in PLanetInRange Array one after other.

6
  • It's unclear what you're trying to do. Please provide a concrete example. Commented Sep 22, 2012 at 7:54
  • I have an array as - var planetNotInRange = new int[7] ; var result = planetSign.Select((b, k) => b.Equals(tempFrind) ? k : -1).Where(k => k != -1).ToArray(); this is in loop will give a number of array of integers. Now I want to concat in PLanetInRange Array one after other. Commented Sep 22, 2012 at 7:55
  • Don't add it as a comment - edit full details into your question. Commented Sep 22, 2012 at 7:56
  • 1
    Do you mean add or merge two arrays? Commented Sep 22, 2012 at 7:58
  • Indeed - it's still not clear what the result should be. Please read tinyurl.com/so-hints. Until your question is clear, it's wasting everyone's time - including your own. Note that you can't increase the size of an array - you can either replace the elements, or you can create a new array. Commented Sep 22, 2012 at 8:00

1 Answer 1

2

It sounds like you shouldn't have an array to start with, if you want to add elements to it. Once an array has been created, its size is fixed.

Use a List<int> instead, and you can use

list.AddRange(array);

I'd usually advise using lists (and other collection types) over arrays anyway. Arrays are useful, obviously, but they're somewhat more primitive and low-level than other collections.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.