Every variable in c# is struct or class or enum
Every variable in C# has a type, and that type is either a value type or a reference type. In some cases, all value types are classified as struct
, and all reference types are classified as class
, but that's not usual. If that is what you meant, then the "or enum" is redundant, because they are value types. If that's not what you meant, there are some cases you overlooked, such as interface types.
Which class arr is an object of?
arr
is an object of type int[]
. int[]
is a reference type which derives from System.Array
, but it's a stretch to call it a class type unless you call all reference types class types.
Why the designers of c# go with the above syntax, why did not they go with the simple ClassName ObjectName = new ClassName() with the arrays too
The "ClassName" is int[]
, so your proposal would lead to int[] arr = new int[](3);
. This is more verbose, does not look familiar to people coming to C# from other languages, and does not actually manage to simplify the language: the language still would need to have special rules for where [
and ]
may be used.