C#中的方法调用本身? [英] method in C# call itself?

查看:66
本文介绍了C#中的方法调用本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在C#调用自身中运行方法吗?

can I run  method in C# call itself?

例如:

public void rndm()
       {
          随机random = new Random();
           int randomNumber = random.Next(0,listBox2.Items.Count);
           listBox2.Select();
           listBox2.SelectedItem = listBox2.Items [randomNumber];
           strsf = listBox2.SelectedItem.ToString();
           if(!activationids.Contains(strsf.Substring(0,1)+ strsf.Substring(2,1)))
           {
                             rndm();
           }
       }

public void rndm()
        {
            Random random = new Random();
            int randomNumber = random.Next(0, listBox2.Items.Count);
            listBox2.Select();
            listBox2.SelectedItem = listBox2.Items[randomNumber];
            strsf = listBox2.SelectedItem.ToString();
            if (!activationids.Contains(strsf.Substring(0, 1) + strsf.Substring(2, 1)))
            {
                rndm();
            }
        }

推荐答案

我可以在C#调用自身中运行方法吗?

can I run  method in C# call itself?

是的

C#中的递归函数
http://www.c -sharpcorner.com/UploadFile/955025/C-Sharp-interview-questions-part4what-is-a-recursive-function-in/

递归变得简单
https://www.codeproject.com/Articles/32873/Recursion-made-simple

-韦恩

Recursive Functions in C#
http://www.c-sharpcorner.com/UploadFile/955025/C-Sharp-interview-questions-part4what-is-a-recursive-function-in/

Recursion made simple
https://www.codeproject.com/Articles/32873/Recursion-made-simple

- Wayne


这篇关于C#中的方法调用本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆