Pages

Topics

Tools

↑↓navigate↵openescclose

All syntax guides

Short, practical guides on programming syntax, language fundamentals, and the tools developers reach for every day.

3,965 guides across 14 topics

Topics

Latest guides

Illustration of a C# generic class with two type parameter slots being filled by concrete type tokens, shown as interlocking geometric blocks.
C#

C# Multiple Generic Type Parameters: Syntax and Usage

c# multiple generic type parameters: Learn how to declare and use C# generic types and methods with multiple type parameters, including constraints, type inference, an...

C# genericsgeneric typestype parameterstype inference
Diagram showing a generic type parameter constrained to unmanaged types, with pointers and stack allocation.
C#

C# where T : unmanaged: Generic Unmanaged Types

Learn how the C# where T : unmanaged constraint enables generic code with pointers, stackalloc, and sizeof, and when to use it.

C# genericsunmanaged typesgeneric constraintsstackalloc
Diagram showing a generic type parameter T with a notnull constraint, excluding nullable types.
C#

C# where T notnull: Generic Constraint Explained

c# where t notnull: Understand the C# notnull generic constraint, how it works with nullable reference types, and when to apply it in your generic APIs.

C# genericstype constraintsnullable reference typesgeneric API design
Illustration of a C# generic type parameter being constructed through a factory metaphor, with a constructor constraint represented visually.
C#

C# where T : new() Constraint: Syntax and Usage

c# where t new: Understand the C# where T : new() constraint: how it requires a parameterless constructor, where it applies, and how to use it safely in generic code.

generic constraintsC# genericstype parametersparameterless constructor
Illustration of a C# generic type parameter T constrained to value types, with solid blocks representing int, DateTime, and enum passing through a filter gate while a reference type is blocked.
C#

C# where T : struct: Generic Value Type Constraints

The C# `where T : struct` constraint restricts generic parameters to non-nullable value types. See how it changes `T?` to `Nullable<T>`, when to use it, and where boxing can still happen.

C#GenericsType ConstraintsValue Types
A C# generic class declaration showing the where T : class constraint restricting type parameters to reference types.
C#

C# where T : class — Reference Type Constraints in Generics

Understand the C# where T : class constraint: syntax, compile-time guarantees, nullability interaction, common mistakes, and runtime behavior.

C#GenericsType Constraints.NET
A diagram showing a generic type parameter T constrained by a class and interface, representing C# where T constraints.
C#

C# where T: Generic Type Constraints Explained

Learn how the C# where T clause constrains generic type parameters, enables compile-time type safety, and covers common constraints like class, struct, new(), and interfaces.

C# genericstype constraintsgeneric methodstype safety
A C# generic constraint diagram showing a type parameter with a where clause restricting it to an interface.
C#

C# Generic Constraints: Syntax, Use Cases, and Pitfalls

Learn how C# generic constraints enforce type requirements at compile time. This guide covers constraint syntax, common patterns, performance implications, and pitfalls.

C# genericsgeneric constraintstype safetycompile-time checking
Diagram showing a generic type parameter acting as a placeholder for multiple concrete types in C#.
C#

C# Generic Type Parameter: Syntax, Constraints, and Runtime Behavior

Learn how C# generic type parameters work: syntax, constraints, variance, runtime behavior, and common mistakes for writing type-safe reusable code.

genericstype safetyconstraintsvariance
Illustration of a generic interface in C# with type parameters and type safety.
C#

C# Generic Interface: Definition, Usage, and Patterns

Learn how to define and use C# generic interfaces for type-safe, reusable abstractions. Includes constraints, covariance and contravariance, and practical repository examples.

C# genericsgeneric interfacestype safetycovariance