title: How to save a C# Custom Class List<> to file stream?
body: <p>I want to save a custom class List (C#) in file stream (in Unity3d). I've already done saving a [Serializable] class saving into memory using this code:</p>
  
  <pre><code>[Serializable]
  public class GameData
  {
  public int Score_SR;
  public float ChaseCredits_SR;
  }
  </code></pre>
  
  <p>Following method for saving the data:</p>
  
  <pre><code>public void Save()
  {
      BinaryFormatter bf = new BinaryFormatter();
      FileStream file = File.Create(Application.persistentDataPath + "/chaserace.cr");
  
      // Save data here from local to orignal data path storage i.e /chaserace.cr
      GameData data = new GameData();
  
      data.Score_SR = Score;
      data.ChaseCredits_SR = ChaseCredits;
      // this take the "data" class data and write it to our "chaserace.cr" file
      bf.Serialize(file , data);
      file.Close();
  }
  </code></pre>
  
  <p>And then use a method Load to load the data. 
  But, now I would like to save a List&lt;> of a custom class "RawData". I've tried doing the same with a List, but could not do that. Maybe there will be an edit within the code that will work for a List&lt;>. </p>
  
  <p>Here is the class whose List I want to save to memory:</p>
  
  <pre><code>[Serializable]
  public class RawData{
  
  public string key; 
  public int level;  
  public string value;
  
  
  public RawData(string key_,string value_,int level_){
      key = key_;
      level = level_;
      value = value_;
  
  }
  }
  </code></pre>
  
  <p>When I try loading data, there is an Error:</p>
  
  <pre><code>BinaryFormatter bf = new BinaryFormatter();
  FileStream file = File.Open(Application.persistentDataPath + "/chaserace.cr", FileMode.Open);
  RawData rawData = (RawData)bf.Deserialize(file);
  List&lt;RawData&gt; rawDataList=rawData; //Here is conversion error
  file.Close();
  </code></pre>