User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 427,499 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,456 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1959 | Replies: 3
Reply
Join Date: Nov 2006
Posts: 8
Reputation: foo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
foo foo is offline Offline
Newbie Poster

Understanding array creation.

  #1  
Nov 10th, 2006
I am still struggling with understanding the creation of objects.
For example.
int[] x = {4,5,6};
int[] y = new int[x.Length];

Why is it that for the first array, we can initialize it without the use of the new keyword yet in the second line, we need the new keyword?
Whats the difference?
Thanks so much.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Understanding array creation.

  #2  
Nov 11th, 2006
Do you have a book to refer back to.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Nov 2006
Posts: 8
Reputation: foo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
foo foo is offline Offline
Newbie Poster

Re: Understanding array creation.

  #3  
Nov 11th, 2006
I think I got it. One creates an instance and fills it.
The other creates it but leaves it empty and with a size. I guess if we are just going to create it, we need the extra step but if we initialize it and fill it, we can short circuit it.
Reply With Quote  
Join Date: Oct 2006
Location: Idaho
Posts: 44
Reputation: Godfear1 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
Godfear1's Avatar
Godfear1 Godfear1 is offline Offline
Light Poster

Re: Understanding array creation.

  #4  
Nov 13th, 2006
Yep. Thats right. Its easy to initialize the array. It is sometimes a pain in the butt to fill it with objects though. You have to create a loop to intialize the individual values (or use the brackets for simple data types.) But you know all this now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 7:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC