如何在C#中创建公共子? [英] How do can I make a public sub in C#?
问题描述
您好,我正在尝试按照YT教程编写Space Invaders。点击这个观看 - > [ ^ ]教程是用Visual Basic编写的,但我试图把它放到c#中。
现在的问题是我不知道如何在c中制作一个合适的公共子,这是让我的外星人在游戏中移动。当你知道它时告诉我。 :)
(PS下面的代码在c#中有点不合适,但我只是把它放在那里给你创意。)
我尝试了什么:
Hello, I am trying to program Space Invaders by following a tutorial on YT. click this one to watch it --> [^] The tutorial was made with Visual Basic but I am trying to put it into c#.
The problem now is I don't know how to make a proper public sub in c, it is to make my aliens in the game move. Tell me when you know it. :)
(P.S. the following code is kinda out of place in c# but I just put it there to give you ideas.)
What I have tried:
#region My subs
public DrawListViewSubItemEventArgs New()
InitializeComponement();
createarray()
end sub
Private sub createarray()
alien(0) = alien1
alien(1) = alien2
alien(2) = alien3
alien(3) = alien4
alien(4) = alien5
alien(5) = alien6
alien(6) = alien7
alien(7) = alien8
alien(8) = alien9
alien(9) = alien10
alien(10) = alien11
alien(11) = alien12
alien(12) = alien13
alien(13) = alien14
alien(14) = alien15
alien(15) = alien16
end sub
#endregion
推荐答案
格式为:
public MyReturnType NameOfMethod(MyParameterType NameOfParamater)
{
MyReturnType result;
...
return result;
}
因此,如果你创建了一个带有一对整数的方法并返回一个总和的字符串:
So if you made a method that takes a pair of integers and returns a string of the sum:
public string GetSumAsString(int x, int y)
{
int sum = x + y;
return sum.ToString();
}
在这种情况下,它不使用任何类方法或变量,因此它可能是 static
( VB中的共享
:
In this case, it doesn't use any class methods or variables, so it could be static
(Shared
in VB):
public static string GetSumAsString(int x, int y)
{
int sum = x + y;
return sum.ToString();
}
如果您打算这么做,请使用代码转换器
代码转换器|由Telerik提供 [ ^ ]
If you're going to do this a lot use a code converter
Code Converter | Provided by Telerik[^]
public void MySub()
{
}
这篇关于如何在C#中创建公共子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!