tagged [c#-8.0]

What is Unknown Nullability in C# 8?

What is Unknown Nullability in C# 8? In C# 8.0 we can have nullable reference types. [The docs](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullability-of-types) state that the...

25 Nov at 01:20

Can a non-nullable reference type in C# 8 be null in runtime?

Can a non-nullable reference type in C# 8 be null in runtime? It seems to me there is really no guarantee that a non-nullable variable won't ever have null. Imagine I have a class that has one propert...

Why is it still possible to assign null to non nullable reference type?

Why is it still possible to assign null to non nullable reference type? I am confused. I thought enabling c# 8 and nullable reference types will prevent the assignment of null to a non nullable refere...

6 May at 04:49

C# 8 understanding await using syntax

C# 8 understanding await using syntax I have next method: Everything fine and clear, connection will be d

Converting a nullable reference type to a non-nullable reference type, less verbosely

Converting a nullable reference type to a non-nullable reference type, less verbosely Is there a way I can convert a nullable reference type to non-nullable reference type in the below example less ve...

10 Apr at 20:34

Calling C# interface default method from implementing class

Calling C# interface default method from implementing class C# 8 supports default method implementations in interfaces. My idea was to inject a logging method into classes like this: ``` public interf...

9 Sep at 11:37

How to await all results from an IAsyncEnumerable<>?

How to await all results from an IAsyncEnumerable? I'm tinkering around with the new `IAsyncEnumerable` stuff in C# 8.0. Let's say I've got some method somewhere that I want to consume: I'm aware that...

20 Nov at 10:16

Using blocks in C# switch expression?

Using blocks in C# switch expression? I fail to find documentation addressing this issue. (perhaps I am just bad at using google...) My guess is that the answer is negative, however I didn't understan...

14 Jan at 08:8

Can we use Records in C# 8.0?

Can we use Records in C# 8.0? I have a project using .NET Standard 2.1 and .NET core 3.1 - so the C# version is 8.0 According to a few articles I found (e.g. [one](https://blog.cdemi.io/whats-coming-i...

25 May at 11:38

Default implementation in interface is not seen by the compiler?

Default implementation in interface is not seen by the compiler? Here is a my code inside a c# project that targets .NET Core 3.0 (so I should be in C# 8.0) with Visual Studio 2019 (16.3.9) ``` public...

20 Nov at 10:39

Asynchonously deserializing a list using System.Text.Json

Asynchonously deserializing a list using System.Text.Json Lets say that I request a large json file that contains a list of many objects. I don't want them to be in memory all at once, but I would rat...

IAsyncEnumerable not working in C# 8.0 preview

IAsyncEnumerable not working in C# 8.0 preview I was playing around with C# 8.0 preview and can't get `IAsyncEnumerable` to work. I tried the following ``` public static async IAsyncEnumerable Get() ...

6 Dec at 13:8

Why declare a local function static in C# 8.0

Why declare a local function static in C# 8.0 In C# 8.0, [Static Local Functions are announced](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#static-local-functions) Can anyone he...

7 Nov at 09:36

Nullable reference type in C#8 when using DTO classes with an ORM

Nullable reference type in C#8 when using DTO classes with an ORM I activated this feature in a project having data transfer object (DTO) classes, as given below: But I get the error: > `CS

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

Can you use IAsyncEnumerable in Razor pages to progressively display markup? I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and...

What's the difference between returning AsyncEnumerable with EnumeratorCancellation or looping WithCancellation

What's the difference between returning AsyncEnumerable with EnumeratorCancellation or looping WithCancellation I have the following method that reads a csv document from a http stream ``` public asyn...

15 Jun at 13:4

C# 8 switch expression for void methods

C# 8 switch expression for void methods I'm aware of the `C# 8` `switch expression` syntax for methods that return a value or for property matching. But if we just need to switch on a string value and...

What does null! statement mean?

What does null! statement mean? I've recently seen the following code: ``` public class Person { //line 1 public string FirstName { get; } //line 2 public string LastName { get; } = null!; /...

8 Apr at 09:31

C#8 nullable : string.IsNullOrEmpty is not understood by compiler as helping for guarding against null

C#8 nullable : string.IsNullOrEmpty is not understood by compiler as helping for guarding against null I am using C# 8 with .NET framework 4.8 I'm currently guarding against a potential string that ca...

Relationship between C# 8.0, NET Core 3.0 and Visual Studio

Relationship between C# 8.0, NET Core 3.0 and Visual Studio The article [Building C# 8.0](https://blogs.msdn.microsoft.com/dotnet/2018/11/12/building-c-8-0/) states > The current plan is that C# 8.0 w...

14 Jul at 03:15

Compiler error of "Non-nullable field is uninitialized" even though it was initialized in InitializeComponents function

Compiler error of "Non-nullable field is uninitialized" even though it was initialized in InitializeComponents function In WinForms it is common that a common initialization function is initializing r...

C# 8 base interface's default method invocation workaround

C# 8 base interface's default method invocation workaround According to [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods](https://lear...

18 Dec at 18:20

Return IAsyncEnumerable from an async method

Return IAsyncEnumerable from an async method Take the following the methods: ``` public async IAsyncEnumerable Foo() { await SomeAsyncMethod(); return Bar(); // Throws since you can not return value...

How do I specify "any non-nullable type" as a generic type parameter constraint?

How do I specify "any non-nullable type" as a generic type parameter constraint? The post is specific to C# 8. Let's assume I want to have this method: If my `.csproj` looks like this (i.e. C# 8 and n...

A problem with Nullable types and Generics in C# 8

A problem with Nullable types and Generics in C# 8 After adding [enable or #nullable enable](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types), I ran into the followi...