Unity List 查找元素索引 - FindIndex 方法代码示例
在 Unity 中,可以使用 List 的 FindIndex 方法来检测一个元素是 List 中的第几个元素。下面是一个示例代码:\n\nc#\nusing System.Collections.Generic;\n\nList<int> myList = new List<int>() { 1, 2, 3, 4, 5 };\nint elementToFind = 3;\n\nint index = myList.FindIndex(item => item == elementToFind);\nif (index != -1)\n{\n Debug.Log("Element found at index: " + index);\n}\nelse\n{\n Debug.Log("Element not found in the list.");\n}\n\n\n在上面的代码中,我们首先创建了一个 List
原文地址: https://www.cveoy.top/t/topic/pPnP 著作权归作者所有。请勿转载和采集!