SA1121.md

December 3, 2025 ยท View on GitHub

SA1121

TypeName SA1121UseBuiltInTypeAlias
CheckId SA1121
Category Readability Rules

Cause

The code uses one of the basic C# types, but does not use the built-in alias for the type.

Rule description

A violation of this rule occurs when one of the following types are used anywhere in the code: Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Object, SByte, Single, String, UInt16, UInt32, UInt64.

A violation also occurs when any of these types are represented in the code using the full namespace for the type: System.Boolean, System.Byte, System.Char, System.Decimal, System.Double, System.Int16, System.Int32, System.Int64, System.Object, System.SByte, System.Single, System.String, System.UInt16, System.UInt32, System.UInt64.

Rather than using the type name or the fully-qualified type name, the built-in aliases for these types should always be used: bool, byte, char, decimal, double, short, int, long, object, sbyte, float, string, ushort, uint, ulong.

The following table lists each of these types in all three formats:

Type AliasTypeFully Qualified Type
boolBooleanSystem.Boolean
byteByteSystem.Byte
charCharSystem.Char
decimalDecimalSystem.Decimal
doubleDoubleSystem.Double
shortInt16System.Int16
intInt32System.Int32
longInt64System.Int64
objectObjectSystem.Object
sbyteSByteSystem.SByte
floatSingleSystem.Single
stringStringSystem.String
ushortUInt16System.UInt16
uintUInt32System.UInt32
ulongUInt64System.UInt64

Native-sized integers (C# 11 and .NET 7 or later)

The native-sized integer aliases nint and nuint were introduced in C# 9. SA1121 considers IntPtr/UIntPtr and their aliases starting in C# 11 when targeting .NET 7 or later (detected via System.Runtime.CompilerServices.RuntimeFeature.NumericIntPtr). In earlier language versions or runtimes, including C# 9, these types do not trigger SA1121 diagnostics.

How to fix violations

To fix a violation of this rule, replace the type with the built-in alias for the type.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed.")]
#pragma warning disable SA1121 // UseBuiltInTypeAlias
#pragma warning restore SA1121 // UseBuiltInTypeAlias