In this tutorial, we are going to discuss the new features in C# 11. To begin with,
How to use C# 11.0?
Let us understand the IDE and version requirements to use C# 11.0. In my below article, I have explained the .NET 7.0 Preview version and the installation steps.
The tools which I have used for this tutorial are
- Microsoft Visual Studio Community 2022 (64-bit) – Current
- Version 17.4.0 Preview 2.1
- .NET 7.0
- Console App
Let us look at some of my favorite features of C# 11.0
- Raw String Literals
- Pattern Matching List
- New Line in Interpolation
- Auto-Default struct
- Required Keyword
The source can be downloaded from GitHub
Raw String Literals
Raw string literals can be
- Multiline
- Contains quotes
- Contains special characters without escape sequences.
- Contains string interpolations.
I have provided a very simple example to explain the difference between Raw String Literals and old approach.
using System.Text;
namespace CSharp11Features.RawLiteralString
{
internal class DisplayRawStrings
{
public static string OldApproach()
{
var _rawstring = new StringBuilder();
_rawstring.Append("I'm explaining \"raw string\" here with escape character");
return _rawstring.ToString();
}
public static string NewApproach()
{
var _rawstring = new StringBuilder();
_rawstring.Append("""I'm explaining "raw string" here without escape character""");
return _rawstring.ToString();
}
public static string InterpolationApproach()
{
var firstName = "Prasad";
var _rawstring = $$"""
{
"firstName" : "{{firstName}}"
}
""";
return _rawstring;
}
}
}
The output of the above code will be,

Raw literals will be created starts with three or more double quotes and end with three or more double quotes.
Pattern Matching List
The below example provides an overview of List pattern matching
namespace CSharp11Features.PatternMatching
{
internal class ListPatternExample
{
static int[] numbers = { 1, 2, 3 };
public static bool IsMatch()
{
var match = numbers is [1, 2, 3];
return match;
}
public static bool IsNotMatch()
{
var match = numbers is [1, 2, 4];
return match;
}
public static bool IsMatchWithExpression()
{
var match = numbers is [0 or 1, <=2, >=3];
return match;
}
}
}



Join the conversation! Your thoughts help the community grow.