update on   5 min read Manikandan csharp

whats new in C# 14.0

In nov,2025 Microsoft officially released C# 14.0 with lot of new features. In this article, i will discuss about what's new in C# 14.0?

In nov,2025 Microsoft officially released C# 14.0 with lot of new features. In this article, i will discuss about what's new in C# 14.0?

Intro

Recently Microsoft released C# 14.0 with lot of new features . More over , re-structuring existing features to make it more easy to understand and more readable.

Listin down the new features in C# 14.0

1.Field-backed Properties
2.Extension Members
3.Null-Conditional Assignment
4.User-defined Compound Assignment Operators
5.Partial Constructors/Events
6.Modifier Support on Lambda Params
7.Implicit Span Conversions
8.Nameof Supports Unbound Generics
9.Primary Constructors for Classes
10.Ref Fields and Scoped Modifiers

Field-backed Properties

Field-backed properties allows direct access to the field without declaring an explicit field. its directly access hidden compiled backend field of an auto implemented property usint the new contextual keyword field.

In Early version of C# , we have to write lot of code to create properties.

private string _message;
public string Message
{
get => _message;
set => _message = value ?? throw new ArgumentNullException(nameof(value));
}
How Field-backed Properties Work in C# 14

• The field keyword is only available inside the get/set/accessor methods of an auto-implemented property. • You can write logic in accessors while enjoying the brevity of auto-properties.

public string Message
{
get;
set => field = value ?? throw new ArgumentNullException(nameof(value));
}

Extension Members

Extension members allow you to add members to existing types without modifying the type’s source code. This feature is particularly useful when you want to add functionality to types that you don’t have control over, such as third-party libraries or built-in types.

public static class StringExtensions
{
public static int WordCount(this string str)
=> str.Split(new char[] { ' ', '\t', '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries).Length;
}

You can then use the extension method as if it were a member of the type.

string text = "Hello, World!";
int count = text.WordCount();

Extension members are a powerful feature that can help you write more maintainable and reusable code.

Now , In C# 14 , changed the way to define extension members.

public static class StringExtensions
{
Extension(string str)
{
public int WordCount() => str.Split(new char[] { ' ', '\t', '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}

You can then use the extension method as if it were a member of the type.

string text = "Hello, World!";
int count = text.WordCount();

What is the difference Existing Implementations?

  • its not maintain all member as a static member. means we allow non-static members inside extension members.
  • Beginner friendly way to define extension members.
  • its not use this Keyword if it mentioned inside extension .
  • if all member are consumed same type then we can have a single grouped extension member.
Example-1

Here, I have showed some extention method existing approach for string type.

public static class StringExtensions
{
public static int WordCount(this string str) =>
str.Split([' ', '.', '?'], StringSplitOptions.RemoveEmptyEntries).Length;
public static string Reverse(this string str)
=> new string(str.ToCharArray().Reverse().ToArray());
public static bool IsNumeric(this string str)
=>str.All(char.IsDigit);
}

What if I need to have integer type extension members? will have another class to define extension members for integer type, like below

public static class IntExtensions
{
public static bool IsEven(this int number)
=> number % 2 == 0;
public static bool IsOdd(this int number)
=> number % 2 != 0;
}

In new Implementation , we can group all extension members for same type. like below

public static class NewExtension
{
extension(string str)
{
public int NewWordCount()
=> str.Split([' ', '.', '?'], StringSplitOptions.RemoveEmptyEntries).Length;
public string NewReverse()
=> new string(str.ToCharArray().Reverse().ToArray());
public bool NewIsNumeric()
=> str.All(char.IsDigit);
}
extension(int number)
{
public bool NewIsEven() => number % 2 == 0;
public bool NewIsOdd() => number % 2 != 0;
}
}

You can then use the extension method as if it were a member of the type and thers is no changes in calling/implementation.

var Name = "My New Extensions";
Console.WriteLine("This one From word Count Traditional way: "+ Name.WordCount());
Console.WriteLine("This one From word Count Traditional way: "+ Name.Reverse());
Console.WriteLine("This one From word Count New way: "+Name.NewIsNumeric());

Null-Conditional Assignment

Null-conditional assignment is a feature that allows you to assign a value to a property or field only if the target object is not null. This feature is particularly useful when you want to avoid null reference exceptions.

public class Person
{
public string? Name { get; set; }
public int Age { get; set; }
}
Person person = null;
person?.Name = "John"; // This will not throw a null reference exception
person?.Age = 30; // This will not throw a null reference exception

User-defined Compound Assignment Operators

User-defined compound assignment operators allow you to define custom behavior for compound assignment operators, such as +=, -=, *=, /=, and %=.

public class Person
{
public string? Name { get; set; }
public int Age { get; set; }
}
Person person = null;
person?.Name = "John"; // This will not throw a null reference exception
person?.Age = 30; // This will not throw a null reference exception

Partial Constructors/Events

Partial constructors allow you to define multiple constructors for a type, each with different parameters. This feature is particularly useful when you want to avoid null reference exceptions.

public class Person
{
public string? Name { get; set; }
public int Age { get; set; }
}
Person person = null;
person?.Name = "John"; // This will not throw a null reference exception
person?.Age = 30; // This will not throw a null reference exception

Modifier Support on Lambda Params

to be added soon …

Implicit Span Conversions

to be added soon …

Nameof Supports Unbound Generics

to be added soon …

Primary Constructors for Classes

to be added soon …

Ref Fields and Scoped Modifiers

to be added soon …

[Top]

Share:
Back to Blog

Related Posts

View All Posts »
What's Csharp scripting?

What's Csharp scripting?

Microsoft recently released .NET 10 with a new feature called .NET Scripting. Here i will discuss about what's csharp scripting?

Manikandan
5 min read