Replies: 3 comments 1 reply
-
Three observations ... ... generally speaking, new language features need to offer more value than simply providing an alternative syntax for something that's already possible. ... function style syntax was well known at the time C# was first designed - in fact, it was used in Delphi's Object Pascal language, designed by Anders Hejlsberg, the original language designer of C#. While I don't know what they were, I'm sure the designers had good reasons for sticking with the C style ... introducing this style of cast would be a breaking change - the LDM is generally very reluctant to take on breaking changes unless they provide a great deal of value. |
Beta Was this translation helpful? Give feedback.
-
You can define a method like this to allow fluent casting: public static T As<T>(object o) where T : class => (T)o; It doesn't work for structs, or cast operators. |
Beta Was this translation helpful? Give feedback.
-
I find |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The current syntax for typecast requires unnecessary bracketing eg:
((Myclass)(x.obj1.obj2)).data
(int)(3.14+xyz)
if we leave this pathetic syntax of c/c++ typecasting and adopt function like syntax, the above can easily be written as:
Myclass(x.obj1.obj2).data
Beta Was this translation helpful? Give feedback.
All reactions