{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1556","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1556/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1556/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1556/events","html_url":"https://github.com/dotnet/csharplang/issues/1556","id":325597484,"node_id":"MDU6SXNzdWUzMjU1OTc0ODQ=","number":1556,"title":"Suggestion: return void and yield IEnumerable","user":{"login":"JackTheSpades","id":20504528,"node_id":"MDQ6VXNlcjIwNTA0NTI4","avatar_url":"https://avatars0.githubusercontent.com/u/20504528?v=4","gravatar_id":"","url":"https://api.github.com/users/JackTheSpades","html_url":"https://github.com/JackTheSpades","followers_url":"https://api.github.com/users/JackTheSpades/followers","following_url":"https://api.github.com/users/JackTheSpades/following{/other_user}","gists_url":"https://api.github.com/users/JackTheSpades/gists{/gist_id}","starred_url":"https://api.github.com/users/JackTheSpades/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JackTheSpades/subscriptions","organizations_url":"https://api.github.com/users/JackTheSpades/orgs","repos_url":"https://api.github.com/users/JackTheSpades/repos","events_url":"https://api.github.com/users/JackTheSpades/events{/privacy}","received_events_url":"https://api.github.com/users/JackTheSpades/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-05-23T08:19:50Z","updated_at":"2018-07-07T06:13:23Z","closed_at":"2018-07-07T06:13:23Z","author_association":"NONE","body":"This is honestly a really minor thing, but I run into it so frequently, that I just thought I'd at least point out my ideas.\r\n\r\n#### 1. Be able to use `return` with void methods to support one liners.\r\n\r\n```cs\r\npublic class Foo\r\n{\r\n    public void DoSomething(string someParam) { ... }\r\n    \r\n    public void SomethingBody()\r\n    {\r\n    \tif(expr)\r\n        \treturn DoSomething(\"Bar\");\r\n        //...\r\n    }\r\n    \r\n    public void SomethingLambda()\r\n    \t=> DoSomething(\"Baz\");\r\n}\r\n```\r\n\r\nIn the example above the expression `return DoSomething(\"Bar\");` would fail as it is used now as void Methods do not allow something to follow the `return`. The Lambda Expression (`=>`) on the other hand does, in a way, support this.\r\n\r\nMy 'concern', if you will, is that if it wasn't for the void type, this would work just fine (e.g. if both `DoSomething` and `SomethingBody` returned an `int`).\r\n\r\nI, in many cases, had to remove the return type of methods only to then be forced to adjust such one liners with a pair of braces.\r\n\r\nYes, this is a very minor thing for people like me who'd rather have things be one-liners but I honestly don't see the problem in void Methods simply executing the expression following the return and ignoring whatever it evaluates to.\r\n\r\nE.g.\r\n```cs\r\npublic class Foo\r\n{    \r\n    public void DoSomething() { ... }\r\n    public double DoMath() { ... }\r\n\r\n    public void SomethingBody()\r\n    {\r\n    \tswitch(param)\r\n        {\r\n            //returns void\r\n            case expr1:\r\n                return DoSomething();\r\n            //ignore returned double value\r\n            case expr2:\r\n                return DoMath();\r\n            //valid but pointless (compiler warning?)\r\n            case expr3:\r\n                return 3 + 4;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n#### 2. Use `yield` in combination with `IEnumerable` values\r\n\r\nAs it stands, when writing Methods that return `IEnumerable<T>` the option to use `yield return (T)` is much appreciated. In combination with abstract or virtual Methods, it is somewhat frustrating to override.\r\n\r\n```cs\r\npublic class Foo\r\n{    \r\n    public virtual IEnumerable<int> Count()\r\n    {\r\n    \tyield return 1;\r\n    \tyield return 2;\r\n    \tyield return 3;\r\n    }\r\n}\r\npublic class Bar : Foo\r\n{\r\n    public override IEnumerable<int> Count()\r\n    {\r\n        foreach(int i in base.Count())\r\n            yield return i;\r\n    \tyield return 4;\r\n    \tyield return 5;\r\n    \tyield return 6;\r\n    }\r\n}\r\n```\r\n\r\nTo give just one example of dealing with other `IEnumerable<T>` Methods. It'd be nice if this could be simplified to a single expression. For example:\r\n\r\n```cs\r\npublic class Bar : Foo\r\n{\r\n    public override IEnumerable<int> Count()\r\n    {\r\n        yield return foreach base.Count();\r\n    \tyield return 4;\r\n    \tyield return 5;\r\n    \tyield return 6;\r\n    }\r\n}\r\n```\r\n\r\nOr something of a similar nature.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/403192071","html_url":"https://github.com/dotnet/csharplang/issues/1556#issuecomment-403192071","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1556","id":403192071,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzE5MjA3MQ==","user":{"login":"jcouv","id":12466233,"node_id":"MDQ6VXNlcjEyNDY2MjMz","avatar_url":"https://avatars2.githubusercontent.com/u/12466233?v=4","gravatar_id":"","url":"https://api.github.com/users/jcouv","html_url":"https://github.com/jcouv","followers_url":"https://api.github.com/users/jcouv/followers","following_url":"https://api.github.com/users/jcouv/following{/other_user}","gists_url":"https://api.github.com/users/jcouv/gists{/gist_id}","starred_url":"https://api.github.com/users/jcouv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcouv/subscriptions","organizations_url":"https://api.github.com/users/jcouv/orgs","repos_url":"https://api.github.com/users/jcouv/repos","events_url":"https://api.github.com/users/jcouv/events{/privacy}","received_events_url":"https://api.github.com/users/jcouv/received_events","type":"User","site_admin":false},"created_at":"2018-07-07T06:13:23Z","updated_at":"2018-07-07T06:13:23Z","author_association":"MEMBER","body":"Both parts are indeed duplicates. Thanks @orthoxerox \r\nI'll go ahead and close this issue."}}
{"actor":{"display_login":"jcouv"}}