问题描述
我可以在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#中的递归函数
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#中的方法调用本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!