gpt4 book ai didi

VB.NET "For each"与 ".GetUpperBound(0)"

转载 作者:行者123 更新时间:2023-12-04 20:42:44 25 4
gpt4 key购买 nike

我想知道什么是首选...

    Dim sLines() As String = s.Split(NewLine)

对于每个:
    For Each sLines_item As String In sLines

.GetUpperBound:
    For i As Integer = 0 To sLines.GetUpperBound(0)

我不知道为什么在这种情况下引入了“For Each”。到目前为止,我只使用了 .GetUpperBound,并且我没有看到“For Each”的任何 PRO。

谢谢

ps:当我使用 ."GetUpperBound(0)"时,我知道我正在迭代向量。
相反,“For Each”听起来像是“我不在乎向量以何种顺序提供给我”。但这只是个人喜好,我想。

最佳答案

简短回答:不要使用 GetUpperBound() . GetUpperBound()的唯一优势是它适用于多维数组,其中 Length不起作用。然而,即使这种用法已经过时了,因为有 Array.GetLength()可用,需要 dimension范围。对于所有其他用途,For i = 0 to Array.Length - 1更好,可能是最快的选择。

关于VB.NET "For each"与 ".GetUpperBound(0)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com