473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Create Arrays in C#

Sorry, just starting, so want to make sure I get all this right:
What is the difference between

int[] values = new int[] { 1,2,3,4,5,6 };

vs

int[] values = { 1,2,3,4,5,6 };

The "new" statement is omitted in the second statement.

I know it is the same, but why use one against the other ..

Regards
Nov 15 '05 #1
1 1165
Im starting out too Krish, but according to my book the 'new' way is the
proper but redundant way of doing this HOWEVER it goes on to say that you
would want to use the new method if you want to assign a new array to an
already initialised array reference e.g.

using System;

class demo{

public static void Main(){
int[] nums=new int[] {10,11,12,13};
Console.Write("Numbers:");
Display(nums);

//resize existing array and values
//you could also use... nums=new int[2] {55,64}
nums=new int[] {55,64};

Console.WriteLine();
Console.Write("Numbers:");

Display(nums);
}

private static void Display(int[] n){
foreach (int i in n){
Console.Write(" "+i);
}
}
}

"Krish" <sk*******@snet.net> wrote in message
news:87**************************@posting.google.c om...
Sorry, just starting, so want to make sure I get all this right:
What is the difference between

int[] values = new int[] { 1,2,3,4,5,6 };

vs

int[] values = { 1,2,3,4,5,6 };

The "new" statement is omitted in the second statement.

I know it is the same, but why use one against the other ..

Regards

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bart Nessux | last post by:
How is this done in php? I've tried several variations of the following: contact_array = ($_POST, $_POST, $_POST, $_POST, $_POST); The ultimate goal is to insert the array into a table in...
8
by: Raymond H. | last post by:
Hello, 1- How to see, in a Label, the URL of a link that the mouse pass over? (in the WebBrower control in a vb projet). 2- How to create a menu and a submenu via a button Command1? and...
3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
1
by: yaya via DotNetMonster.com | last post by:
Let's say I wana create a set of arrays A1,A2,A3.... so if I use a for loop, can I create the arrays ? for(int i=0; i<3; i++) { int A(i+1) = new int; } ^ | A1,A2,A3
6
by: Christian Blackburn | last post by:
Hi Gang, I can't seem to figure out how to create an object array in VB.NET 2003. In VB6 you would just select an object copy and paste it and that was that. I don't know why in the heck they...
11
by: Gene | last post by:
I want to create a certain number of arrays on the same time to use, is it possible to do that?
34
by: Tom | last post by:
I'd greatly appreciate advice and code snippets on how to create a ram disk within a C/C++ program. I also need to be able to determine the free space. Thanks in advance for any help.
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I am using vb.net 2005 and the following code trying to create varible at runtime: For n=1 to 4 dim v+n.tostring(n) as double Next n the resone behaind using the previous...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.