Feature Request: Implicit/Implied Return Object #1912
Replies: 6 comments
-
Even in languages that support something like this your example would fail as the default value of a With |
Beta Was this translation helpful? Give feedback.
-
Is there a reason why your code isn't written like this? public List<List<String>> GetFilesInBuckets()
{
return Directory.EnumerateDirectories(bfolderPath)
.Select(s => Directory.EnumerateFiles(s, "*.exe").ToList()).ToList();
} |
Beta Was this translation helpful? Give feedback.
-
@HaloFour I agree now, Probably isn't the best idea. Was thinking of a simple substitution type instance for a default constructor object, but I don't know what goes on behind the scenes. I had hundreds of those type methods in a project, some would change a bit and I would have to edit the code, so I guess it would be a specific case. @svick |
Beta Was this translation helpful? Give feedback.
-
@svick
Just trying to avoid having the type if it is implied in the return. Probably still not such a good idea. |
Beta Was this translation helpful? Give feedback.
-
It is very unlikely that a language feature is considered when the main use case boils down to "we want to work around our code guidelines". |
Beta Was this translation helpful? Give feedback.
-
I was reading this and felt like I had to leave this for future readers
C# 6+ This is one statement. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If you need to return an object that requires processing, you are forced to declare an object, same as 1980s C++:
I wonder if something like this could be implemented:
I often deal with complex, nested dictionary return types and it is just extra lines of boilerplate code to maintain. Sometimes the return type changes, and there is more code to fix. I know there is Deconstruct and Throwaways - this would seem like a nice addition to that. Throwaway is a single underscore, implied return object is a double. A declared double underscore in the sub would override this feature.
In a perfect world, in this use case
return
could go away too 😁Beta Was this translation helpful? Give feedback.
All reactions