What are all the array initialization syntaxes that are possible with C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
In case you want to initialize a fixed array of pre-initialized equal (non-
null
or other thandefault
) elements, use this:Also please take part in this discussion.
Example to create an array of a custom class
Below is the class definition.
This is how you can initialize the array:
or
or
and in multi dimensional array
Will create array of empty strings repeated 'count' times. In case you want to initialize array with same yet special default element value. Careful with reference types, all elements will refer same object.
Repeat without LINQ: