UpperBound of Dynamic array
-
Hello, Please I want to get the upperbound of a dynamic array, is there a function in c# to achive this? thanks.
-
Hello, Please I want to get the upperbound of a dynamic array, is there a function in c# to achive this? thanks.
Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.
-
Hello, Please I want to get the upperbound of a dynamic array, is there a function in c# to achive this? thanks.
You can find how many elements are in an array with the Length property. C# doesn't have dynamic arrays - they are all fixed when you declare them, but you can fake it by creating a new array and copying the old elements to it. This is not a dynamic array however, as only the references you specifically change have the new size.
int\[\] orig = new int\[\] { 1, 2, 3, 4, 5, 6 }; int\[\] copy = orig; int\[\] temp = new int\[10\]; for (int i = 0; i < copy.Length; i++) { temp\[i\] = copy\[i\]; } copy = temp;
"copy" now refers to an array of ints with ten elements, but "orig" tsill referes to an array of six. If you want a dynamic array like structure, you would be better off using a List<T> which has a ToArray method if you need it.
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
You can find how many elements are in an array with the Length property. C# doesn't have dynamic arrays - they are all fixed when you declare them, but you can fake it by creating a new array and copying the old elements to it. This is not a dynamic array however, as only the references you specifically change have the new size.
int\[\] orig = new int\[\] { 1, 2, 3, 4, 5, 6 }; int\[\] copy = orig; int\[\] temp = new int\[10\]; for (int i = 0; i < copy.Length; i++) { temp\[i\] = copy\[i\]; } copy = temp;
"copy" now refers to an array of ints with ten elements, but "orig" tsill referes to an array of six. If you want a dynamic array like structure, you would be better off using a List<T> which has a ToArray method if you need it.
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
OriginalGriff wrote:
If you want a dynamic array like structure, you would be better off using a List
Or switch to VB? :laugh:
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
-
OriginalGriff wrote:
If you want a dynamic array like structure, you would be better off using a List
Or switch to VB? :laugh:
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
riced wrote:
Or switch to VB?
Wash your keyboard out with soap! I would never recommend anyone switch to VB. Well, except Estate Agents. :laugh:
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
OriginalGriff wrote:
If you want a dynamic array like structure, you would be better off using a List
Or switch to VB? :laugh:
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
The smiley saved you from a 1 vote :-)
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners. -
Hello, Please I want to get the upperbound of a dynamic array, is there a function in c# to achive this? thanks.
Where did you find a dynamic array? :confused:
-
Where did you find a dynamic array? :confused:
He looked under the VB sofa and there it was. :laugh:
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
-
You can find how many elements are in an array with the Length property. C# doesn't have dynamic arrays - they are all fixed when you declare them, but you can fake it by creating a new array and copying the old elements to it. This is not a dynamic array however, as only the references you specifically change have the new size.
int\[\] orig = new int\[\] { 1, 2, 3, 4, 5, 6 }; int\[\] copy = orig; int\[\] temp = new int\[10\]; for (int i = 0; i < copy.Length; i++) { temp\[i\] = copy\[i\]; } copy = temp;
"copy" now refers to an array of ints with ten elements, but "orig" tsill referes to an array of six. If you want a dynamic array like structure, you would be better off using a List<T> which has a ToArray method if you need it.
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
Thanks all, I discovered that when using the foreach... loop to access an array, you don't need to know the dimension before hand. it works great. thanks again for your contributions