Caminhoneiro

Array of delegates

Mar 29th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1.          // define a delegate type to match the required method signature
  2.          delegate void SpawnRocksMethod();
  3.          void CreateList()
  4.          {
  5.              // create a list of delegate objects as placeholders for the methods.
  6.              // note the methods must all be of type void with no parameters
  7.              // that is they must all have the same signature.
  8.              List<SpawnRocksMethod> spawnRocks = new List<SpawnRocksMethod>();
  9.              spawnRocks.Add(spawnRocks1);
  10.              spawnRocks.Add(spawnRocks2);
  11.              // call a method ...
  12.              spawnRocks[0]();
  13.          }
  14.          //confirmed working
  15.          void spawnRocks1()
  16.          {
  17.              Instantiate something;
  18.          }
  19.          void spawnRocks2()
  20.          {
  21.              Instantiate something;
  22.          }
Advertisement
Add Comment
Please, Sign In to add comment