csharplang | official repo for the design of the C # programming language | Natural Language Processing library
kandi X-RAY | csharplang Summary
kandi X-RAY | csharplang Summary
The official repo for the design of the C# programming language
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of csharplang
csharplang Key Features
csharplang Examples and Code Snippets
Community Discussions
Trending Discussions on csharplang
QUESTION
EDIT: I've finally found out why I was remembering external interface implementations possibly being a feature, it is because months ago I must have been reading the static abstract interface members proposal at around the same time as this discussion (specifically the part under "Explicit implementation and disambiguation") and the two must have merged in my mind over time.
I've been playing around with static abstract interface members, and I was wondering if it is possible to somehow tell the compiler how a specific type implements a specific interface even though the type doesn't actually implement the interface in its declaration. That is, is it possible to implement the interface externally?
I'm asking this because I remember that when I first learned about static abstract interface members months ago, this was supposed to be one of the features I learned about, but I can't find the source of these claims again (I'm 90% sure it was a youtube video).
Has this ever been planned? Is it going to be implemented?
An example of what I mean:
...ANSWER
Answered 2022-Mar-21 at 16:41If the Type you have uses the partial keyword on the class definition, then you will be able to modify a class, to use an interface. But if the type is defined as immutable, and doesn't permit to DI behaviour, then the short answer is no.
QUESTION
Say I have a request model object:
...ANSWER
Answered 2022-Mar-01 at 19:08You have a model with an optional value. Within a user-defined method you validate that this value is defined. The compiler can't determine this behaviour and thous the warning.
To help the compiler you could use the null-forgiving operator like this:
QUESTION
I have this code
...ANSWER
Answered 2021-Dec-18 at 11:14An init-only property doesn't require that properties are set at creation time with the property initializer syntax. It allows them to be set that way instead of requiring that all read-only properties are set by constructors.
So with your code,
QUESTION
When I try to compile source code from command line with Microsoft's Visual C# Compiler (v4.8.4084.0), I get the following error and/or warning:
PS C:\> csc Program.cs
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
As part of the Roslyn Project, C# 7.0 language features are currently being developed; but the current version of C# programming language is C# 10. Is there a way to use C# 7.0 higher language features from the command line?
...ANSWER
Answered 2021-Dec-17 at 08:38Try opening the *.csproj file and adding to the tag. I added it to both DEBUG and RELEASE tags.
QUESTION
Info: that's still not applicable to C# 9 Was planned for C# 10, but even from that #10 was recently moved away... Source: https://github.com/dotnet/csharplang/issues/2691
Original question body starts here:
With C# 9 the syntax for Dependency Inversion (Injection via ctor) was simplified.
From:
...ANSWER
Answered 2021-Feb-25 at 07:59Not an answer really. It's too early for the feature :)
As @Yair mentioned: That's still not applicable to C# 9.
I've found the url to the docs: https://github.com/dotnet/csharplang/issues/2691
According to it: Was planned for 10.0 Candidate in Language Version Planning, but unfortunately was removed from it on 6 February 2021 (probably for a later version)
For now I am going to mark the question as resolved, but will come with a proper answer later, when we'll have fun with PrimaryContructors
- that's how we will call them.
Thanks for tolerance
QUESTION
In https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/nullable-reference-types-specification.md#element-access the following code is used, which I don't understand and I haven't found any documentation:
...ANSWER
Answered 2020-Nov-22 at 15:27It is part of the C# pattern matching language feature, although not named explicitly as such.
The documentation about recursive pattern matching mentions it in the property pattern section, showing the ways to check for not null giving an example for a string
.
Note that a null-checking pattern falls out of a trivial property pattern. To check if the string s is non-null, you can write any of the following forms
QUESTION
The C# 9 records feature specification includes the following:
A record type contains two copying members:
A constructor taking a single argument of the record type. It is referred to as a "copy constructor". A synthesized public parameterless instance "clone" method with a compiler-reserved name
But I cannot seem to call either of these two copying members:
...ANSWER
Answered 2020-Oct-11 at 18:09But what about cloning?
QUESTION
C# 8 added the ranges syntax to C#:
...ANSWER
Answered 2020-Sep-28 at 07:27There are a lot of design decisions that just won't have satisfying answers. However, this one at least has a paper-trail you can follow in the design notes (in one or more mentions) starting at the following link.
Note : This was just an arbitrary decision, the reason they chose exclusive is because they chose exclusive. It could easily not have been the case due to the pros and cons
C# Language Design Notes for Jan 22, 2018
...
Conclusion
Let us go with
..
means exclusive. Since we've chosen to focus on the indexing/slicing scenario, this seems the right thing to do:
- It allows
a.Length
as an endpoint without adding/subtracting 1.- It lets the end of one range be the beginning of the next without overlap
- It avoids ugly empty ranges of the form
x..x-1
And as @vc74 mentions in the comments and also stated in the document supplied, other languages like python follow this convention, however others don't
QUESTION
After adding enable
or #nullable enable
, I ran into the following problem with my Generic methods:
This does not work:
...ANSWER
Answered 2020-May-21 at 07:19Explanation of the problem
The problem in your first code sample occurs because compiler differently handles nullable value types and nullable reference types:
- Nullable value type
T?
is represented by typeNullable
. - Nullable reference type
T?
is the same typeT
but with a compiler-generated attribute annotating it.
Compiler cannot generate code to cover this both cases at the same time, therefore a compilation error occurs. And this error forces us to specify class
or struct
constraint. This behavior is also stated in the C# specification
:
For a type parameter
T
,T?
is only allowed ifT
is known to be a value type or known to be a reference type.
A good explanation of this problem can be found in this article: Try out Nullable Reference Types. Scroll to the paragraph "The issue with T?
".
A workaround to fix the problem
The next workaround can be used if you don't want to create two methods with different names and suppress warnings:
QUESTION
I have added a code in my startup class (.net core 3.1) to return the type based on parameter and I get compile-time errors.
I have created a running example in sharplab. if switch expression contains the string or other objects it runs fine.
working example 1:
...ANSWER
Answered 2020-May-08 at 20:37You should explicitly declare a type of handler, instead of var
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install csharplang
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page