Skip to content

Latest commit

 

History

History
71 lines (53 loc) · 2.4 KB

File metadata and controls

71 lines (53 loc) · 2.4 KB
title Methods and Return Values
actions
checkAnswer
hints
material
editor
language startingCode answer
c#
public class AlienFinder : SmartContract { public class Alien { public uint xna; public string alienName; } public static void Main (string alienName) { ulong randomNumber; uint xna; Alien someAlien = new Alien (); } // Enter your answer here }
public class AlienFinder : SmartContract { public class Alien { public uint xna; public string alienName; } public static void Main (string alienName) { ulong randomNumber; uint xna; Alien someAlien = new Alien (); } private static ulong RandomNumber () { } private static uint FindXna (ulong n) { } }

Tag: C# Basics

Returning to the contract itself:

Methods in C# follow the template below:

<Access_Specifier> <static> <Return_Type> Method_Name (<Parameters>) { }
  • Access_Specifier can be public, 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_Type defines the data type that the method returnsvoid ,if the method has no return data.
  • <Parameters> are defined using the format Data_Type Data_Name eg: (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.

Instructions:

  • 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