Hello. what is a common way to check the boundary of C# array or list<> officially? It seems to be not supported official MS documents. Thanks. I expected like that int [] arr = new int[105]; bool iterate(int idx) { if (false == arr.RangedIn(idx)) return false; ..... }
myArr.Length will tell you the length of an array. myList.Count will tell you the number of elements in a list. Code (CSharp): int myIndex; bool indexIsInList = myIndex > 0 && myIndex < myList.Count; bool indexIsInArray = myIndex > 0 && myIndex < myArray.Length;