2023-09-05 csharpdotnetdotnet-8 .NET 8 – Include non-public members in JSON serialization Learn how to include private, protected, and internal properties in JSON serialization in .NET 8 using the JsonInclude attribute.
2023-08-31 csharp C# 12 – Inline arrays Inline arrays enable you to create an array of fixed size in a struct type. Such a struct, with an inline buffer, should provide performance comparable to an unsafe fixed size buffer. Inline arrays are mostly to be used by the runtime team and some library authors to improve performance in certain scenarios. You likely…
2023-08-30 csharp C# 12 – Collection expressions C# 12 introduces a new simplified syntax for creating arrays. It looks like this: It’s important to note that the array type needs to be specified explicitly, so you cannot use var for declaring the variable. Similarly, if you wanted to create a Span<int>, you can do: Multi-dimensional arrays The advantages of this terse syntax…
2023-08-11 csharpdotnet C# How to wait for a process to end? You can use the WaitForExit method to wait for the process to complete. Your code will wait synchronously for the process to finish, then it will resume execution. Let’s look at an example: The code above will start a new cmd.exe process, and execute the timeout 5 command. The process.WaitForExit() call will force your program…
2023-08-06 csharp C# 12 – Alias any type The using alias directive has been relaxed in C# 12 to allow aliasing any sort of type, not just named types. This means that you can now alias tuples, pointers, array types, generic types, etc. So instead of using the full structural form of a tuple, you can now alias it with a short descriptive…
2023-08-05 csharp Is there a C# With…End With statement equivalent? The With…End With statement in VB allows you to execute a series of statements that repeatedly refer to a single object. Thus the statements can use a simplified syntax for accessing members of the object. For example: Is there a C# syntax equivalent? No. There is not. The closest thing to it would be the…
2023-07-30 csharp C# 12 – Primary constructors Starting from C# 12, it is possible to define a primary constructor within classes and structs. The parameters are placed in parentheses right after the type name. The parameters of a primary constructor have a broad scope. They can be utilized to initialize properties or fields, serve as variables in methods or local functions, and…
2023-06-11 csharpdotnet How to start programming with C# A beginner's guide to getting started with C# programming, from setting up Visual Studio to writing your first program and finding learning resources.
2023-06-10 csharp How to switch to C# 12 Fix C# 12 language version errors by updating your target framework to .NET 8 or setting LangVersion in your .csproj file.
2023-06-10 csharp What’s new in C# 12 An overview of new features in C# 12, including primary constructors, default lambda parameters, collection expressions, inline arrays, and more.