{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1813","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1813/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1813/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1813/events","html_url":"https://github.com/dotnet/csharplang/issues/1813","id":353945134,"node_id":"MDU6SXNzdWUzNTM5NDUxMzQ=","number":1813,"title":"Question: Can we restrict the scope of internally declared our parameters?","user":{"login":"Korporal","id":12262952,"node_id":"MDQ6VXNlcjEyMjYyOTUy","avatar_url":"https://avatars0.githubusercontent.com/u/12262952?v=4","gravatar_id":"","url":"https://api.github.com/users/Korporal","html_url":"https://github.com/Korporal","followers_url":"https://api.github.com/users/Korporal/followers","following_url":"https://api.github.com/users/Korporal/following{/other_user}","gists_url":"https://api.github.com/users/Korporal/gists{/gist_id}","starred_url":"https://api.github.com/users/Korporal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Korporal/subscriptions","organizations_url":"https://api.github.com/users/Korporal/orgs","repos_url":"https://api.github.com/users/Korporal/repos","events_url":"https://api.github.com/users/Korporal/events{/privacy}","received_events_url":"https://api.github.com/users/Korporal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-08-24T22:18:24Z","updated_at":"2018-08-27T17:57:58Z","closed_at":null,"author_association":"NONE","body":"I'm reading this [article ](https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/)and it says \r\n\r\n> In Preview 4, the scope rules are more restrictive: Out variables are scoped to the statement they are declared in. Thus, the above example will not work until a later release.\r\n\r\nHowever I was wondering if it is not preferable to _retain_ greater scope restrictions. I'd like to a fragment like this:\r\n\r\n```\r\nif (TryGetSomething(someKey, out var something))\r\n{\r\n   // do stuff with something\r\n}\r\n\r\nsomething.x = true; \r\n```\r\n\r\nto generate a compiler error for the last line, by making the declared \"something\" out of scope outside of the \"if\" block.\r\n\r\nWhy was this not done? If I want it to not be out of scope then I'd simply declare it before the \"if\" block.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/416312705","html_url":"https://github.com/dotnet/csharplang/issues/1813#issuecomment-416312705","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1813","id":416312705,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjMxMjcwNQ==","user":{"login":"Korporal","id":12262952,"node_id":"MDQ6VXNlcjEyMjYyOTUy","avatar_url":"https://avatars0.githubusercontent.com/u/12262952?v=4","gravatar_id":"","url":"https://api.github.com/users/Korporal","html_url":"https://github.com/Korporal","followers_url":"https://api.github.com/users/Korporal/followers","following_url":"https://api.github.com/users/Korporal/following{/other_user}","gists_url":"https://api.github.com/users/Korporal/gists{/gist_id}","starred_url":"https://api.github.com/users/Korporal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Korporal/subscriptions","organizations_url":"https://api.github.com/users/Korporal/orgs","repos_url":"https://api.github.com/users/Korporal/repos","events_url":"https://api.github.com/users/Korporal/events{/privacy}","received_events_url":"https://api.github.com/users/Korporal/received_events","type":"User","site_admin":false},"created_at":"2018-08-27T17:57:58Z","updated_at":"2018-08-27T17:57:58Z","author_association":"NONE","body":"@AustinBryan - Jon's concerns are very reasonable, but I would have argued that the price is worth paying because one can always declare the variable in the old way and get what they want. \r\n\r\n\r\n\r\n```\r\npublic void DoSomethingWithFoo()\r\n{\r\n    // return because the whole method depends on foo\r\n    if (!TryGetSomething(someKey, out var foo)) return;   \r\n\r\n    // do something with foo\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"Korporal"}}