Questions tagged [c#-8.0]

1

votes
1

answer
341

Views

C# 8 positional pattern vs. deconstruction pattern

In the first proposal of pattern matching the recursive pattern was defined with the following grammar: recursive_pattern : positional_pattern | property_pattern ; Link: https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md To demonstrate the positional pattern, .Net team has use th...
Bassam Alugili
1

votes
1

answer
37

Views

When C#8 is released, on what frameworks will it run on?

When C# 8 is released, will it be targeting .NET Core 3.x only or will it be able to target existing frameworks too? If so, which ones?
Andy
0

votes
0

answer
9

Views

Why IAsyncEnumerator doesn't have the Reset method in C#-8?

Why IAsyncEnumerator doesn't have the Reset method ? It only has the Current property and the MoveNextAsync() method. public interface IAsyncEnumerator : IAsyncDisposable { T Current { get; } ValueTask MoveNextAsync(); }
Hrant Khangulyan
1

votes
1

answer
11

Views

What is the default value of Non-Nullable reference types in C# 8?

If I enable nullable reference types , what will be the value of the following string if I declare it like so ? string text;
Hrant Khangulyan
6

votes
3

answer
178

Views

What happens with returning IEnumerable if used with async/await (streaming data from SQL Server with Dapper)?

I am using Dapper to stream data from a very large set in SQL Server. It works fine with returning IEnumerable and calling Query(), but when I switch to QueryAsync(), it seems that the program tries to read all of the data from SQL Server instead of streaming. According to this question, it should w...
Ilya Chernomordik
4

votes
1

answer
26

Views

Minimal installation of C# 8 command-line compiler for “dotnet build”

We need to install the new C# 8 command-line compiler on our Jenkins server. We found the 'Build Tools for Visual Studio 2019' package on the Visual Studio Downloads page, but when we select the '.NET Core build tools' workload, it wants to install almost 2GB of stuff. This is a problem, as our Jenk...
Joe White
1

votes
0

answer
5

Views

Multiple cases in c# 8.0 switch

In traditional c# switch we have such construction,where we can aggregate multiple cases. How can it be done in new c# 8.0 switch construction ? switch (value) { case 1: case 2: case 3: //do some stuff break; case 4: case 5: case 6: //do some different stuff break; default: //default stuff break; }
alekoo73
1

votes
2

answer
0

Views

How to mark a NonNullable reference property as safe? [duplicate]

This question already has an answer here: Non-nullable string type, how to use with Asp.Net Core options 1 answer I have an entity which I use in my EntityFramework model. public class Entity { public int Id { get; set; } public string Value { get; set; } } After enabling nullable reference types c...
Shahriar Gholami
4

votes
3

answer
95

Views

What is Range and Index types in c# 8?

In c# 8 add two new types to System namespace as System.Index and System.Range How work this classes and When can use them?
Hamed Naeemaei
1

votes
1

answer
43

Views

How to mark a default return value in C# 8 as nullable for classes only?

I'm currently trying to apply the new C# 8.0 non-nullable reference type feature to existing code, and don't know how to fix the CS8603 warning in the following data deserialization method: T ReadOptional() where T : IEntity, new() { if (ReadBoolean()) { T instance = new T(); instance.Read(this); //...
Ray Koopa
1

votes
1

answer
60

Views

Can I define C# 8 beta compatible indexers in C# 7?

It seems, that they require System.Index and System.Range I can't find any NuGet packages that would provide these, similar to ValueTuple
LOST
1

votes
2

answer
103

Views

What is the difference between NullableContextOptions and NullableReferenceTypes?

I've been playing with new c# 8.0 NullableReferenceTypes feature for a while. And I'm little bit confused about turning this feature on via changing .csproj file. I mean in order to enable this feature you have to put the following lines in your .csproj file: 8.0 enable But also I've found another o...
isxaker
0

votes
0

answer
33

Views

The best practice when using c# 8.0 null reference type during deserialization

I am trying the c# 8.0 and want to enable the null reference type check for the whole project. And I hope I could improve my code design, but not to disable this check in some code scope. I met a problem when I deserialize an object graph. The object have reference with each other, but for the final...
watson
6

votes
3

answer
233

Views

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

The article Building C# 8.0 states The current plan is that C# 8.0 will ship at the same time as .NET Core 3.0. However, the features will start to come alive with the previews of Visual Studio 2019 that we are working on. What is the relationship between C# 8.0, NET Core 3.0 and Visual Studio? As a...
kimsagro
1

votes
0

answer
45

Views

By which criteria range is applied to arrays and strings in C#8?

I'm looking through C#8 ranges and cannot understand how exactly the application of the Range is restricted to arrays and strings only. I have thought that it is somehow related to interface array implements. It implements ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructur...
Alex Netkachov
42

votes
2

answer
1.4k

Views

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!; //assign null is possible public string? MiddleName {get; } = null; public Person(string firstName, string lastName, string middleName) { FirstName...
isxaker
1

votes
1

answer
0

Views

C# 8.0 availability in Visual Studio 2017?

I'd like to use C# 8.0 (especially ranges and non-nullable reference types). I only found some information that there is a preview of it in the new VS2019 (even that is 2 months old now). Are there any plans that C# 8.0 is eventually also coming to VS17?
nonsensation
0

votes
0

answer
21

Views

Does default implementation of Interface members in C# 8 relates to overcome multiple inheritance problem of abstract class?

I'm reading this blog of .NET Engineering Team and they have introduced a new feature of default implementation for Interface. I'm confused related to its motive other than multiple level inheritance problem of abstract class. Other than that I'm not able to figure out any other benefit. Consdier th...
iSahilSharma
5

votes
2

answer
145

Views

IAsyncEnumerable<> broken in VS 2019 preview 2 (Core 3.0 preview 1)

After installing VS 2019 preview 2 i get a great number of errors. Error demo code: public class Class1 { public static async IAsyncEnumerable Get() { for( int i = 0; i < 10; i++ ) { await Task.Delay( 100 ); yield return i; } } } and nothig more (a new dll project)! With preview 1 was ok. The proj...
me-on-stov
131

votes
1

answer
5.8k

Views

Why doesn't the new hat-operator index from the C# 8 array-slicing feature start at 0?

C# 8.0 introduces a convenient way to slice arrays - see official C# 8.0 blogpost. The syntax to access the last element of an array is int value[] = { 10, 11, 12, 13 }; int a = value[^1]; // 13 int b = value[^2]; // 12 I'm wondering why the indexing for accessing the elements backwards starts at...
Michael Pittino
0

votes
2

answer
91

Views

Default interface methods and default values for Auto Properties

Given that an auto property compiles to a get_method, a set_method and a private variable and since C# 8 is introducing default interface methods Can properties in Interfaces have default implementations? Especially a get only property?
John Demetriou
1

votes
1

answer
109

Views

How to enable Nullable Reference Types feature of C# 8.0 for the whole project

According to the anouncement of the new C# 8.0 feature named 'nullable reference types' it can be enabled for the whole project. (mentioned here: https://youtu.be/VdC0aoa7ung?t=137) But how to enable it for the project? Did not find any new appropriate option in Project Properties window in Visual S...
dthpth
3

votes
3

answer
160

Views

C# 8 - multiple inheritance “abstract class”? [duplicate]

This question already has an answer here: Default Interface Implementations. What is deep meaningful difference now, between abstract class and interface? 3 answers It seems to me like the C# 8.0 feature, default interface member implementation, essentially allows one to create implementations at t...
Lasooch
1

votes
3

answer
123

Views

Does C# 8 annotate nullable properties and parameters?

I'm curious about how nullable reference types work, not in your own codebase, but with an already compiled library. Will C# be able to know if a property or parameter is nullable, perhaps checking the existance of some compiler-added attribute?
Max Toro
3

votes
1

answer
133

Views

Can new C# language features be used to to clean-up Task.WhenAll syntax?

With 'async everywhere', the ability to fire off multiple heterogeneous operations is becoming more frequent. The current Task.WhenAll method returns its results as an array and requires all tasks to return the same kind of object which makes its usage a bit clumsy. I'd like to be able to write......
NeilMacMullen
3

votes
2

answer
1.2k

Views

If default interface methods are implemented in C# 8.0 why would I ever need abstract classes? [closed]

I recently ran into a list of features that are being considered for addition in the next version of C#. One of them is called 'default interface methods': https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md In short, it will allow you to define actual method impl...
Marko
42

votes
8

answer
17.5k

Views

How would you implement a “trait” design-pattern in C#?

I know the feature doesn't exist in C#, but PHP recently added a feature called Traits which I thought was a bit silly at first until I started thinking about it. Say I have a base class called Client. Client has a single property called Name. Now I'm developing a re-usable application that will be...
mpen
4

votes
1

answer
750

Views

Nullable Reference Types with C# 8

Null reference exceptions are one of the top sources of program failures. Tony Hoare called it his billion dollar mistake. So I'm particularly looking forward to C# 8 and the new nullable reference types feature. I think I've got a pretty good grasp of the feature and what it's going to mean for my...
pmcilreavy
8

votes
2

answer
372

Views

Default Interface Methods in C# 8

Consider the following code example: public interface IPlayer { int Attack(int amount); } public interface IPowerPlayer: IPlayer { int IPlayer.Attack(int amount) { return amount + 50; } } public interface ILimitedPlayer: IPlayer { new int Attack(int amount) { return amount + 10; } } public class Pla...
Bassam Alugili
7

votes
3

answer
433

Views

Default Interface Implementations. What is deep meaningful difference now, between abstract class and interface?

I know that an abstract class is a special kind of class that cannot be instantiated. An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for al...
Tornike Gomareli
4

votes
3

answer
97

Views

C# 8 - multiple inheritance “abstract class”?

It seems to me like the C# 8.0 feature, default interface member implementation, essentially allows one to create implementations at the interface level. Pairing that with the fact that a class can implement multiple interfaces, it seems eerily close to a multiple inheritance structure for classes....
Lasooch
4

votes
2

answer
102

Views

Determine if type reference is nullable/non-nullable

Using the upcoming C# 8 nullable reference type feature, how can I tell if the type signature for a field/method/ property etc is a nullable or non-nullable reference type at runtime?
Craig Smitham