【发布时间】:2015-04-18 16:53:54
【问题描述】:
在下面的教程示例代码中,我了解其中大部分是如何工作的。不过,有几件事我不明白。请帮助我理解其中一些字符的用途以及它们的用途。我将在下面解释我不明白的地方。
Module paramByref
Sub swap(ByRef x As Integer, ByRef y As Integer)
Dim temp As Integer
temp = x ' save the value of x
x = y ' put y into x
y = temp 'put temp into y
End Sub
Sub Main()
' local variable definition
Dim a As Integer = 100
Dim b As Integer = 200
Console.WriteLine("Before swap, value of a : {0}", a)
Console.WriteLine("Before swap, value of b : {0}", b)
' calling a function to swap the values '
swap(a, b)
Console.WriteLine("After swap, value of a : {0}", a)
Console.WriteLine("After swap, value of b : {0}", b)
Console.ReadLine()
End Sub
End Module
我不明白为什么需要x、y 和temp。为什么不保留a 和b 的声明并交换值?
另外,在Console.WriteLine 上,我知道{0} 是第n 个引用或索引位置,但逗号建议输出其他内容。是说在 0 索引中输出 a 的值吗?如果是这样,只能有一个零索引,那么为什么下一行引用零索引的值?还是我在这方面都错了?任何解释都将不胜感激......请为这个新手降低你的答案。
【问题讨论】:
标签: vb.net