Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can someone help me regarding how strings as parameters work?

Discussion in 'Scripting' started by anydayzz, Jul 31, 2016.

  1. anydayzz

    anydayzz

    Joined:
    Feb 13, 2016
    Posts:
    111
    For example what is best for performance of the following:

    1:
    EventManager.SomeEvent("Hi");
    void SomeEventListener(string someString){}

    2:
    string someString;
    ...

    someString = "Hi";
    EventManager.SomeEvent(ref someString);
    void SomeEventListener(ref string someString){}
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,738
    don't worry about performance, stuff like this is a drop in the bucket. Only use the ref keyword, if you absolutely need to for your use case, since it can make your code pretty bug prone.
     
    anydayzz likes this.
  3. anydayzz

    anydayzz

    Joined:
    Feb 13, 2016
    Posts:
    111
    Thanks.