Tag: csharp
77 posts · Page 6 of 8
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.
2023-05-09 csharp
C# 12 – Default values for parameters in lambda expressions
C# 12 lets you specify default parameter values and params arrays in lambda expressions, just like in methods and local functions.
2023-03-21 csharp
C# 11 – Generic attributes
Learn how to define and use generic attributes in C# 11, including restrictions on type arguments and common error messages.