Browse by Topic

Popular

Latest

Latest C# Posts

Illustration showing the flow of try, catch, and finally blocks in C# exception handling.
C#

C# Try Catch Finally: How the Blocks Actually Behave

Understand how try, catch, and finally blocks interact in C#, when the finally block runs, and how to avoid common exception-handling mistakes.

exception handlingC# syntaxtry-catch-finallyerror handling
Illustration of a C# try-catch block showing an exception being caught and handled with a finally block for cleanup.
C#

C# try catch: Syntax, Usage, and Pitfalls

c# try catch: Learn the practical syntax and behavior of the C# try-catch statement, including exception filters, finally, performance implications, and common mistakes.

exception handlingtry-catchC# error handlingfinally block
Illustration of C# exception handling showing a try block with a catch block and an error icon.
C#

C# Exception Handling: Patterns for Robust Code

Practical C# exception handling patterns: try-catch-finally, exception filters, custom exceptions, performance tradeoffs, async code, and result types.

Exception Handlingtry-catchCustom ExceptionsException Filters
Diagram showing covariant and contravariant assignment directions between generic interfaces with base and derived types.
C#

C# Generic In vs Out: Covariance and Contravariance

Understand C# generics `in` vs `out`: covariance and contravariance, when to use each keyword, and how the compiler enforces these rules.

C# genericscovariancecontravariancetype safety
Diagram illustrating contravariance in C# generics, showing assignment of a base type to a derived type parameter.
C#

C# Generic Contravariance: How It Works

Learn how C# generic contravariance lets base-type implementations work with derived types, including practical interface and delegate examples.

C#GenericsVarianceContravariance
Diagram showing a covariant generic interface allowing assignment from IEnumerable<string> to IEnumerable<object>
C#

C# Generic Covariance: How It Works and Where to Use It

Understand C# generic covariance with practical examples, including how the out keyword enables safe type substitution in interfaces and delegates.

C#GenericsCovarianceType Safety
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