FunctionFormalParameter.cs 649 B

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System;
  3. namespace Examples
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public class FunctionFormalParameter : MonoBehaviour
  9. {
  10. private void Start()
  11. {
  12. Trigger(PrintString);
  13. }
  14. /// <summary>
  15. /// 带有函数形参的函数
  16. /// </summary>
  17. /// <param name="formalMethod"></param>
  18. private void Trigger(Action<string> formalMethod)
  19. {
  20. formalMethod("printsomething");
  21. return;
  22. }
  23. /// <summary>
  24. /// 被传入的形参函数
  25. /// </summary>
  26. private void PrintString(string message)
  27. {
  28. Debug.Log("FormalParameter:" + message);
  29. return;
  30. }
  31. }
  32. }