| TypeName | SA1000KeywordsMustBeSpacedCorrectly |
| CheckId | SA1000 |
| Category | Spacing Rules |
The spacing around a C# keyword is incorrect.
A violation of this rule occurs when the spacing around a keyword is incorrect.
The following C# keywords should always be followed by a single space: and, await, case, catch, fixed, for,
foreach, from, group, if, in, is, into, join, let, lock, not, orderby, or, out, ref, return, select,
switch, using, var, where, while, yield.
The checked, default, nameof, sizeof, typeof, and unchecked keywords should not be followed by any space, except in the following cases:
- The
defaultkeyword is used as a c# 7.1 default literal expression. In this case it can both have and not have trailing spaces.
The new and stackalloc keywords should always be followed by a space, except in the following cases:
- The
neworstackallockeyword is used to create a new implicitly-typed array. In this case there should be no space between the keyword and the opening array bracket. - The
newkeyword is part of implicit object creation (target-typed new). In this case there should be no space between the keyword and the opening parenthesis. - The
newkeyword is part of a generic type constraint. In this case there should be no space between thenewkeyword and the opening parenthesis.
The throw keyword should always be followed by a space, unless it is part of a re-throw statement, in which case there
should be no space between the throw keyword and the semicolon.
In C# 9 function pointer syntax, the delegate keyword must not be followed by a space before the *, and the
unmanaged keyword must not be followed by a space before the optional calling convention list. For example,
delegate*<int, void> and delegate* unmanaged[Cdecl]<int, void> show the expected spacing for this feature.
To fix a violation of this rule, add or remove a space after the keyword, according to the description above.
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1000:KeywordsMustBeSpacedCorrectly", Justification = "Reviewed.")]#pragma warning disable SA1000 // KeywordsMustBeSpacedCorrectly
#pragma warning restore SA1000 // KeywordsMustBeSpacedCorrectly