Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于List扩展ForEach的混淆问题 #112

Open
zxTheX opened this issue Jun 27, 2023 · 0 comments
Open

关于List扩展ForEach的混淆问题 #112

zxTheX opened this issue Jun 27, 2023 · 0 comments

Comments

@zxTheX
Copy link

zxTheX commented Jun 27, 2023

#if UNITY_EDITOR

        // v1 No.6
        [MethodAPI]
        [APIDescriptionCN("遍历 List (可获得索引)")]
        [APIDescriptionEN("foreach List (can get index)")]
        [APIExampleCode(@"
var testList = new List<string> {""a"", ""b"", ""c"" };
testList.Foreach((c,index)=>Debug.Log(index)); 
// 1, 2, 3,
")]
#endif
        public static void ForEach<T>(this List<T> list, Action<int, T> action)
        {
            for (var i = 0; i < list.Count; i++)
            {
                action(i, list[i]);
            }
        }

方法传参的action中index在前,而注释里的index在后。注释和API需要改变其中一个,否则ForEach<int>的调用会产生混淆
ps:对于js/ts index在后是正确的,而考虑兼容性就不方便改变已有API,但二者必改其一

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant