C# FAQ: What is the difference between CSharp and Java array declarations

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

What is the difference between C# and Java array declarations?

In the Java language, there are two methods of declaring arrays. The first method is backwards compatible with C and C++ notation. The second is generally acknowleged as being more easily read and maintained.

C# uses only the second array declaration syntax. The following are examples in both the C# and Java languages:

// C# example
int[] intArray     = new int[10];   // intArray is a type int[] object
float floatArray[] = new float[10]; // compile error 
// Java example
int[] intArray     = new int[10];   // intArray is a type int[] object
float floatArray[] = new float[10]; // floatArray is a type float[] object 

See also



Personal tools