Proposal: Universal Property Access in C# #9302
Replies: 5 comments 2 replies
-
If ths
|
Beta Was this translation helpful? Give feedback.
-
That's the official and built in explanation which I understand. I'm
thinking it would be better if things can be implemented in a better and
more streamlined way. A language is always what we want it to be.
…On Thu, 10 Apr 2025, 11:59 HaloFour, ***@***.***> wrote:
String.IsNullOrEmpty(String) be String.NullOrEmpty
If ths string is null you can't call an instance property on it. It will
throw a NullReferenceException.
int.TypeOf rather than typeof(int)
typeof(int) isn't a method call, it's a built-in way to obtain a Type
instance for a given type
—
Reply to this email directly, view it on GitHub
<#9302 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP4OLFY5O7LNJUFAWOCOWUD2YZFKFAVCNFSM6AAAAAB23B72ISVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENZZGAZTKNA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
We don't call the The mentioned aspects work differently. Using the same syntax can only increase confusions. |
Beta Was this translation helpful? Give feedback.
-
Maybe a change of syntax philosophy is required. The current state is very
confusing and doesn't come naturally. Thinking outside the box is what's
needed. Evolution will eventually happen, especially if newer easier more
natural languages become more dominant. AI is also helping with the coding.
…On Fri, 11 Apr 2025, 06:26 Huo Yaoyuan, ***@***.***> wrote:
For instance, string.IsNullOrEmpty is a *static method*. The obj.Method
syntax is for *instance method* which always performs null check. The
language feature *extension method* that allows you to use a static
method with the instance method syntax, has always caused confusions .
typeof is a *constant operator*. It creates a constant-like value of
given input (type name). It can be used for constructs that not valid for
other syntaxes, for example the open generic type List<>.
—
Reply to this email directly, view it on GitHub
<#9302 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP4OLF2F3TXFRDBDZXBDLJ32Y5G7HAVCNFSM6AAAAAB23B72ISVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENZZHEZTINI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip!
Very informative chat.
…On Fri, 11 Apr 2025, 11:47 HaloFour, ***@***.***> wrote:
Maybe a change of syntax philosophy is required.
What you're suggesting wouldn't be C#. You're free to create your own
language.
—
Reply to this email directly, view it on GitHub
<#9302 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP4OLFYV2MZQEO3RFZQXY4D2Y6MTXAVCNFSM6AAAAAB23B72ISVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEOBQGI2TEOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
A more universal way to access properties, like having all of them follow the Type.property pattern rather than some being property(Type), could indeed enhance consistency and readability in C#. It could simplify the learning curve for new developers and make the codebase more uniform.
For instance:
String.IsNullOrEmpty(String) be String.NullOrEmpty
int.TypeOf rather than typeof(int)
Summary:
This proposal suggests a unified approach for accessing properties and methods in C# using the syntax. This enhancement aims to improve consistency, readability, and developer experience by eliminating disparities between static and instance-bound property access, as well as simplifying overloading and parameterized properties.
Problem Statement:
Currently, in C#, properties and methods use different access patterns:
This creates inconsistency and can lead to confusion, especially for new developers or when working across different APIs.
Proposed Solution:
Adopt a universal property access mechanism that uses for all properties and methods.
Beta Was this translation helpful? Give feedback.
All reactions