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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Is AsReadOnly required?

Discussion in 'Scripting' started by phoda, Apr 3, 2020.

  1. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    Code (CSharp):
    1. public IReadOnlyList<int> GetChildDir() {
    2.         return childDir;
    3.         //return childDir.AsReadOnly();
    4.     }
    What is the difference from return and commented return
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
  3. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    Um sorry if i didnt clarify. Function always returns read only list. List childDir is List<int>. I want to return it as read only but my question is what is difference between returning just list iwthout .AsReadOnly(). since in both i cant access functions like add and remove