{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/5449","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/5449/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/5449/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/5449/events","html_url":"https://github.com/dotnet/corefx/issues/5449","id":126817541,"number":5449,"title":"ForRef and MapRef extension method for array","user":{"login":"Thaina","id":1042507,"avatar_url":"https://avatars.githubusercontent.com/u/1042507?v=3","gravatar_id":"","url":"https://api.github.com/users/Thaina","html_url":"https://github.com/Thaina","followers_url":"https://api.github.com/users/Thaina/followers","following_url":"https://api.github.com/users/Thaina/following{/other_user}","gists_url":"https://api.github.com/users/Thaina/gists{/gist_id}","starred_url":"https://api.github.com/users/Thaina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thaina/subscriptions","organizations_url":"https://api.github.com/users/Thaina/orgs","repos_url":"https://api.github.com/users/Thaina/repos","events_url":"https://api.github.com/users/Thaina/events{/privacy}","received_events_url":"https://api.github.com/users/Thaina/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-01-15T06:49:11Z","updated_at":"2016-01-15T13:24:01Z","closed_at":null,"body":"It is an easy implement to let foreach for reference in array\r\nI want it to be included in official System.Linq library\r\n\r\n```\r\npublic delegate void RefAction<T>(ref T item);\r\npublic static T[] ForRef<T>(this T[] array,RefAction<T> action)\r\n{\r\n    int i = 0;\r\n    while(i < array.Length)\r\n    {\r\n        action(ref array[i]);\r\n        i++;\r\n    }\r\n    return array; /// return self to chain with Linq\r\n}\r\n\r\npublic delegate void RefFunction<T,R>(ref T item,out R obj);\r\npublic static R[] MapRef<T,R>(this T[] array,RefFunction<T,R> func)\r\n{\r\n    int i = 0;\r\n    var res = new R[array.Length];\r\n    while(i < array.Length)\r\n    {\r\n        func(ref array[i],out res[i]);\r\n        i++;\r\n    }\r\n\r\n    return res;\r\n}\r\n```\r\n\r\nAlso it could be great if this pattern also allowed in Dictionary and List\r\n\r\nI want to discus first then I may create a fork and pull request by myself"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/171960106","html_url":"https://github.com/dotnet/corefx/issues/5449#issuecomment-171960106","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/5449","id":171960106,"user":{"login":"Thaina","id":1042507,"avatar_url":"https://avatars.githubusercontent.com/u/1042507?v=3","gravatar_id":"","url":"https://api.github.com/users/Thaina","html_url":"https://github.com/Thaina","followers_url":"https://api.github.com/users/Thaina/followers","following_url":"https://api.github.com/users/Thaina/following{/other_user}","gists_url":"https://api.github.com/users/Thaina/gists{/gist_id}","starred_url":"https://api.github.com/users/Thaina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thaina/subscriptions","organizations_url":"https://api.github.com/users/Thaina/orgs","repos_url":"https://api.github.com/users/Thaina/repos","events_url":"https://api.github.com/users/Thaina/events{/privacy}","received_events_url":"https://api.github.com/users/Thaina/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T13:24:01Z","updated_at":"2016-01-15T13:24:01Z","body":"@mikedn @JonHanna I just state that it could modified and produce new at the same time. We don't need to always done that. I just make it \r\nAnd many times we may not want to produce new array, just modified current, that why I want to have this kind as optional for that purpose\r\n\r\nIf you want to produce new one without modified the old then current Select is well suit\r\n\r\nAnd does current foreach work with all functionality of linq? It's not. It can take\r\n\r\nAs I said. My propose is for working with large struct when you want to modified by reference instead of select new one. And even current Select and foreach can modified object anyway if it not struct. Why you don't have any problem with that?\r\n\r\nIt just allow you don't mean you need to do it"}}