<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">I can't see the point of using .Max
when you have already fixed the array size to 100. It's best used
when you don't know how big the array will be, for example: -<br>
<br>
<i>Public Sub Form_Open()</i><i><br>
</i><i>Dim sList As String[] = Dir(User.Home)</i><i><br>
</i><i><br>
</i><i>For iFile As Integer = 0 To sList.Max</i><i><br>
</i><i> Print sList[iFile]</i><i><br>
</i><i>Next</i><i><br>
</i><i><br>
</i><i>Print</i><i><br>
</i><i>Print "Number of files = " & Str(sList.Max)</i><i><br>
</i><i><br>
</i><i>End</i><i><br>
</i><br>
Charlie<br>
<br>
On 17/03/2019 18:01, Cedron Dawg wrote:<br>
</div>
<blockquote type="cite"
cite="mid:870792830.2844473.1552845686160.JavaMail.zimbra@exede.net">
<pre class="moz-quote-pre" wrap="">I just found out about the .Max property of arrays, saving having to do a .Count - 1.
I like it, but the name is a little confusing to me, I thought it would mean MaxValue, not MaxIndex. No I can't think of a better short word. "Top" is misleading, so is "Limit".
My real question is a performance related one. Given:
Dim a As New String[100]
Dim i, m As Integer
.
.
m = a.Max
For i = 0 To m
...
Next
.
.
For i = 0 To a.Max
...
Next
Does the first loop give any performance advantage over the second one? Or does the compiler recognize that "a" won't change size in the loop and implement the first form under the covers?
----[ Gambas mailing-list is hosted by <a class="moz-txt-link-freetext" href="https://www.hostsharing.net">https://www.hostsharing.net</a> ]----
</pre>
</blockquote>
<br>
</body>
</html>