0% found this document useful (0 votes)
17 views25 pages

Top 5 Features: Aram Tchekrekjian @aramt87

C# 13 introduces five key features: Params Collections allow any collection type with the params modifier, a new Lock Type enhances thread synchronization, a new escape sequence \\e simplifies code, an index operator ^ enables array initialization from the end, and relaxed constraints on ref struct improve performance in generics. These updates enhance code readability, flexibility, and memory efficiency. Overall, C# 13 aims to streamline coding practices and improve performance in various scenarios.

Uploaded by

Pallavi Gond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views25 pages

Top 5 Features: Aram Tchekrekjian @aramt87

C# 13 introduces five key features: Params Collections allow any collection type with the params modifier, a new Lock Type enhances thread synchronization, a new escape sequence \\e simplifies code, an index operator ^ enables array initialization from the end, and relaxed constraints on ref struct improve performance in generics. These updates enhance code readability, flexibility, and memory efficiency. Overall, C# 13 aims to streamline coding practices and improve performance in various scenarios.

Uploaded by

Pallavi Gond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

TOP 5

FEATURES
IN
C# 13

Aram Tchekrekjian @AramT87


1

Params
Collections

@AramT87
Params Collections
Now you can use any
collection type with the
params modifier

Previously, you could only


use an array type to pass
a set of data to a method

@AramT87
Params Collections
Allowed types include
implementations of
IEnumerable<T>, Span<t>,
ReadOnlySpan<T>

And Interfaces of
IEnumerable<T>,
IReadOnlyCollection<T>,
IReadOnlyList<T>,
ICollection<T>,
IList<T>

@AramT87
Params Collections
The addition of Span and
ReadOnlySpan is
particularly useful to help
the compiler reduce the
overhead in memory
consumption

Since the array will be


stored in stack rather than
getting allocated in heap.

@AramT87
Params Collections

@AramT87
2

New
Lock Type

@AramT87
New Lock Type
This new Lock class
improves code
readability, enhances
thread synchronization,
and offers additional
methods for greater
control over lock
behavior.

@AramT87
New Lock Type
Enter() and Exit() for
manual lock
management.
TryEnter() to attempt
immediate lock
acquisition.
EnterScope() for
cleaner lock handling
with using.
IsHeldByCurrentThrea
d checks if the current
thread ow the lock.
@AramT87
New Lock Type

@AramT87
New Lock Type
Output from the previous
example

@AramT87
3

New
Escape
Sequence
\e
@AramT87
New Escape Sequence \e

In C# 13, the \e escape


sequence was introduced
as a shorthand for the ESC
(escape) character with
the Unicode code point
U+001B.

It makes your code more


simple and avoids any
confusion when using
hexadecimal sequences
@AramT87
New Escape Sequence \e
Use cases:

Text processing and


Encoding

Command lines

Command-based
communications in
systems like label
printers, and others.

@AramT87
New Escape Sequence \e

@AramT87
4

Init array
with
index operator ^
(from the end)

@AramT87
Init array with
index operator ^
You can now initialize an
array using the index
operator ^, or better known
as the “index from the end”
operator.

In versions before C# 13,


the ^ operator can't be used
in an object initializer, you
need to index the elements
from the front.
@AramT87
Init array with
index operator ^

This feature is particularly


useful when initializing
collections or arrays
where you want to avoid
the need to calculate
explicit indices manually.

@AramT87
Init array with
index operator ^

@AramT87
5

Relaxed
Constraints on
ref struct
and
ref variables

@AramT87
Relaxed Constraints on
ref struct and ref variables

C# 13 allows ref struct as type


parameters in generic
methods, improving their
flexibility in performance-
critical scenarios.

This feature ensures that


high-performance types like
spans can be used with
generics safely.

@AramT87
Relaxed Constraints on
ref struct and ref variables

@AramT87
Relaxed Constraints on
ref struct and ref variables

Also you can now declare ref


local variables in async and
iterator methods.

@AramT87
TL;DR
Top 5 Features in C# 13

1. Params Collections
2. New Lock Type
3. New Escape Sequence \e
4. Init array with index
operator ^
5. Relaxed constraints on
ref struct and ref
variables
@AramT87
Thank You
Follow me for more content

Aram Tchekrekjian

AramT87

Get Free tips and Tutorials in .NET and C#


Join 800+ Readers
CodingSonata.com/newsletters

You might also like