TypeName | SA1026CodeMustNotContainSpaceAfterNewKeywordInImplicitlyTypedArrayAllocation |
CheckId | SA1026 |
Category | Spacing Rules |
An implicitly typed array allocation within a C# code file is not spaced correctly.
A violation of this rule occurs whenever the code contains an implicitly-typed array allocation which is not spaced correctly. Within an implicitly typed array allocation, there should not be any space or a blank line between the new
or stackalloc
keyword and the opening array bracket. For example:
var a = new[] { 1, 10, 100, 1000 };
Span<int> a = stackalloc[] { 1, 10, 100, 1000 };
To fix a violation of this rule, remove any whitespace between the new
or stackalloc
keyword and the opening array bracket.
#pragma warning disable SA1026 // Code should not contain space after new or stackalloc keyword in implicitly typed array allocation
var ints = new [] { 1, 2, 3 };
#pragma warning restore SA1026 // Code should not contain space after new or stackalloc keyword in implicitly typed array allocation