| title | Methods and Return Values | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| actions |
|
||||||||
| material |
|
Tag: C# Basics
Returning to the contract itself:
Methods in C# follow the template below:
<Access_Specifier> <static> <Return_Type> Method_Name (<Parameters>) { }Access_Specifiercan bepublic,privateand etc.static: if a method has static keyword, it can be invoked directly without creating an object of the class. This keyword can be omitted if the method is not static.Return_Typedefines the data type that the method returnsvoid,if the method has no return data.<Parameters>are defined using the formatData_Type Data_Nameeg:(string alienDna)
To learn more about methods, refer to C# tutorials
So far, the Alien created is only a placeholder. We want to be able to get a random ulong integer, and generate an XNA from that random number.
We will get into the details of how to acquire the random number in the next chapter. For now, we need to declare a method that generates random numbers and a method that finds 'XNA' from the random number.
- Declare two private static methods
- One is called RandomNumber, it has no parameter.
- The other is called FindXna, it has one ulong parameter named
n, and has a return type of uint