问题描述
所以我基本上试图在c#中重用代码,有点像方法(尽管我对如何使用方法有些不确定)。一个例子是,如果我想重新使用几行代码,使几个文本框可见。将非常感谢帮助!
So I'm basically trying to re-use a code within c#, sort of like a method (although I'm a little unsure about how to use methods). An example is if I wanted to re-use several lines of code that makes several textboxes visible. Help will be most appreciated!
推荐答案
void ShowTextboxes()
{
// put the lines that you want to re-use here
}
然后,在您表单中的另一个地方,您可以这样调用您的方法:
Then, on another place in your form, you can call your method like this:
ShowTextboxes();
在这里阅读更多关于方法的信息:
[]
statement1;
statement2;
statement3;
你可以创建一个这样的函数:
You can create a function that does that:
void MyFunction()
{
statement1;
statement2;
statement3;
}
然后可以通过调用函数执行三个语句:
and can then execute the three statements by calling the function:
MyFunction();
这真的是软件开发的第1页,所以我建议你在尝试之前先阅读。
This really is page 1 in software development so I'd advise you read up before trying anything more.
这篇关于我如何重用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!