level 3
才开始学vb.net,对于函数过程和子过程非常晕,尤其是过程里面带数组的时候,就完全不知道该怎么办了。。。
求比较懂的人讲解一下,感激不尽!!!
2013年05月06日 08点05分
1
level 7
虽然想帮你,可是这个还真要自己去看,比如
Public Function A(n as int32) as int32
If n=1 then
Return 1
Else
Return n*A(n-1)
End If
End Function
这是个求n阶乘的函数,注意A是方法名称
2013年05月06日 08点05分
2
我看到书上写的是: function 函数过程名(ParamArray 数组名() as 数据类型) ParamArray是什么意思?
2013年05月06日 08点05分
回复 Melanie_H :数组变量,或者叫数组句柄
2013年05月06日 08点05分
level 7
上面是个递归掉用,求N的阶乘还有其他手段
Private Sub JCFun(ByVal n As Integer, ByRef sum As Integer)
sum = 1
For i As Integer = n To 1 Step -1
sum *= i
Next
End Sub
这个方法和上面完全相同,只不过你要注意2个参数的传址方式,该方法虽然没返回值,但是
sum直接是按地址传递,执行完后你给sum传递的变量就是阶乘结果,只不过你要用变量来传递,常数就结果就丢了
2013年05月06日 08点05分
3
好吧,我慢慢理解。。谢谢!
2013年05月06日 09点05分
level 10
楼上不注意LZ问的什么,是参数是数组的时候。。。。。
Function GetMax(ByVal Str1() As String) As Integer()
Dim LLo() As Integer
If Str1 Is Nothing Then Return Nothing
ReDim LLo(Str1.Length - 1)
For i = 0 To Str1.Length - 1
LLo(i) = CInt(Str1(i)) + 1
Next
Return LLo
End Function
给你个函数参考下,作用:传入一个字符串数组,转为integer再加1,传出数字数组。
2013年05月07日 01点05分
4