c#-8.0

Linq methods for IAsyncEnumerable

≡放荡痞女 提交于 2020-08-26 19:48:29
问题 When working with an IEnumerable<T> there are the build-in extension methods from the System.Linq namespace such as Skip , Where and Select to work with. When Microsoft added IAsyncEnumerable in C#8 did they also add new Linq methods to support this? I could of course implement these methods myself, or maybe find some package which does that, but I'd prefer to use a language-standard method if it exists. 回答1: There is, in the System.Linq.Async namespace from the System.Reactive package. If

Unexpected results after optimizing switch case in Visual Studio with C#8.0

泄露秘密 提交于 2020-08-22 08:08:12
问题 Today while coding, visual studio notified me that my switch case could be optimized. But the code that I had vs the code that visual studio generated from my switch case does not result in the same outcome. The Enum I Used: public enum State { ExampleA, ExampleB, ExampleC }; After the following code runs the value is equal to 2147483647. State stateExample = State.ExampleB; double value; switch (stateExample) { case State.ExampleA: value = BitConverter.ToSingle(BitConverter.GetBytes((long

What is difference between Init-Only and ReadOnly in C# 9?

丶灬走出姿态 提交于 2020-08-10 19:29:46
问题 I am going through C# 9 new features which will be released soon. Init-Only properties are being introduced with it. The one big limitation today is that the properties have to be mutable for object initializers to work: They function by first calling the object’s constructor (the default, parameterless one in this case) and then assigning to the property setters. Init-only properties fix that! They introduce an init accessor that is a variant of the set accessor which can only be called

Visual Studio 2019 project upgrade to C#8 build failed

為{幸葍}努か 提交于 2020-08-09 10:47:34
问题 For one of our projects we're trying to upgrade to use C#8 instead of C#7.1. The upgrade looks like it works, because the compiler looks like it takes C#8 statements (it doesn't mark it as an error). However, when I build the project I get a build failed without any errors showing initially. The code to test C#8 is of the following lines: private string TestCSharp8(int x) { return x switch { 0 => "ZERO", 1 => "ONE", 2 => "TWO", 3 => "THREE", _ => "OTHER" }; } The IDE is accepting this code

Visual Studio 2019 project upgrade to C#8 build failed

一笑奈何 提交于 2020-08-09 10:46:04
问题 For one of our projects we're trying to upgrade to use C#8 instead of C#7.1. The upgrade looks like it works, because the compiler looks like it takes C#8 statements (it doesn't mark it as an error). However, when I build the project I get a build failed without any errors showing initially. The code to test C#8 is of the following lines: private string TestCSharp8(int x) { return x switch { 0 => "ZERO", 1 => "ONE", 2 => "TWO", 3 => "THREE", _ => "OTHER" }; } The IDE is accepting this code

.net core 3.1: 'IAsyncEnumerable<string>' does not contain a definition for 'GetAwaiter'

自作多情 提交于 2020-08-09 06:19:11
问题 I have a .net core 3.1 console app. I have a method with the following signature: public async IAsyncEnumerable<string> GetFilePathsFromRelativePathAsync(string relativePath) If I call it: private async Task<IEnumerable<FileUpload>> GetFileUploadsAsync(string relativePath) { ... var filePaths = await service.GetFilePathsFromRelativePathAsync(relativePath); ... } I get the following error: Error CS1061 'IAsyncEnumerable' does not contain a definition for 'GetAwaiter' and no accessible

What is the difference between an interface with default implementation and abstract class? [duplicate]

余生长醉 提交于 2020-08-02 04:35:15
问题 This question already has answers here : Default Interface Methods. What is deep meaningful difference now, between abstract class and interface? [closed] (6 answers) Closed 10 months ago . C# 8.0 has introduced a new language feature – default implementations of interface members. public interface IRobot { void Talk(string message) { Debug.WriteLine(message); } } The new default interface implementations provides the elements of the traits language. However is is also blurring the line

What is the difference between an interface with default implementation and abstract class? [duplicate]

坚强是说给别人听的谎言 提交于 2020-08-02 04:34:25
问题 This question already has answers here : Default Interface Methods. What is deep meaningful difference now, between abstract class and interface? [closed] (6 answers) Closed 10 months ago . C# 8.0 has introduced a new language feature – default implementations of interface members. public interface IRobot { void Talk(string message) { Debug.WriteLine(message); } } The new default interface implementations provides the elements of the traits language. However is is also blurring the line

The difference between abstract classes and interfaces in C# 8 release? [closed]

℡╲_俬逩灬. 提交于 2020-07-31 03:27:36
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 months ago . Improve this question So in C# 8 interfaces will be able to have actual implementations of methods. At that point, what will be the difference between abstract classes and interfaces and why would I ever use abstract class anymore?What would be the advantage of this change

How to avoid irrelevant nullable warning (without explicit suppression)

扶醉桌前 提交于 2020-07-30 08:08:08
问题 Is there a way to make the analyzer understand that the variable Bar has a value for the following case? #nullable enable class Foo { bool GenerateArray => Bar.HasValue; int? Bar { get; set; } void FooBar() { var data = (GenerateArray) ? new int[Bar.Value] : null; } } There is the warning "Nullable value type may be null." for Bar.Value but it obviously can't be. I am aware of two ways to avoid the warning. Both have disadvantages: Using Bar.HasValue directly instead of the property