首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VB.Net中的递归函数示例

VB.Net中的递归函数示例
EN

Stack Overflow用户
提问于 2011-11-18 10:16:06
回答 4查看 24K关注 0票数 4

我见过other posts,但它们大多是在C#中实现的。对于希望学习递归的人来说,看看VB.Net中的实际工作示例可能会很有帮助。如果有人刚刚接触VB.Net编程,尝试破译和convert C#是一个额外的困难。我确实找到了我现在理解的this post,但如果有一篇VB.Net示例的帖子,我可能已经能够找到它了,faster.This是我提出这个问题的部分原因:

有没有人可以在VB.Net中展示一些简单的递归函数示例?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-11-18 20:35:23

这篇来自维基文章的文章很棒

代码语言:javascript
运行
复制
Sub walkTree(ByVal directory As IO.DirectoryInfo, ByVal pattern As String)
 For Each file In directory.GetFiles(pattern)
    Console.WriteLine(file.FullName)
 Next
 For Each subDir In directory.GetDirectories
    walkTree(subDir, pattern)
 Next
End Sub
票数 3
EN

Stack Overflow用户

发布于 2011-11-18 10:33:56

看看MSDN的文章- Recursive Procedures (Visual Basic)。本文将帮助您理解递归的基础知识。

请参阅以下链接:

  1. Recursive function to read a directory structure
  2. Recursion, why it's cool.
票数 3
EN

Stack Overflow用户

发布于 2011-11-18 22:11:12

经典名著之一

代码语言:javascript
运行
复制
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Try
        Label1.Text = Factorial(20).ToString("n0")
    Catch ex As Exception
        Debug.WriteLine("error")
    End Try
End Sub

Function Factorial(ByVal number As Long) As Long
    If number <= 1 Then
        Return (1)
    Else
        Return number * Factorial(number - 1)
    End If
End Function 'Factorial

在.Net 4.0中,您可以使用BigInteger而不是Long...

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8176993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档