3 Replies - 251 Views - Last Post: 23 July 2012 - 05:24 AM Rate Topic: -----

#1 DrDress  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-July 12

quick creation of arrays

Posted 23 July 2012 - 02:58 AM

Hi

Is there a way to creat an array without creating a variable and filling each space. Something like this:

int[] Array;
Array = {1,2,3};


Like it's done with non-array variables:

int a;
a=1;

Is This A Good Question/Topic? 0
  • +

Replies To: quick creation of arrays

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: quick creation of arrays

Posted 23 July 2012 - 03:33 AM

Your first snippet was very close, the syntax is this:
int[] arr = new int[] { 1, 2, 3 };


Was This Post Helpful? 0
  • +
  • -

#3 DrDress  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-July 12

Re: quick creation of arrays

Posted 23 July 2012 - 04:01 AM

Thanks, but that's not what I meant. I want to change the content AFTER the array is declared, something like this:

int[] arr = new int[] { 1, 2, 3 };

...

arr = new int[] { 4, 5, 6 };


Is this a way to do it?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3424
  • View blog
  • Posts: 10,548
  • Joined: 05-May 12

Re: quick creation of arrays

Posted 23 July 2012 - 05:24 AM

Take a look at Array.Copy().

Other than saving lines of code, I'm not sure what that will buy you because you'll be sacrificing less typing for more memory and more CPU time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1