title: Convert package variable of type System.Object to a List<String> with SSIS C# Script
body: <p>my question is simple yet the headache I get from it is quite serious. In a SSIS package, how can I convert a System.Object package variable at run time  into a list of strings with a C# script so I can then select the Max value from this list and assign back to another package variable. </p>
  
  <p>(Details:)
  In SSIS i have a preceding Cozy Roc task which gets the list of file names from a remote SFTP directory and saves it into a local (package) variable "FilesNamesList" of type System.Object. What I would like to do with a C# script task is to parse this object variable into a list so I can then select the Max Value/File Name and assign it to another package variable "LastFileName" of type string. I will then use this second variable to download only the file with this name thru SFTP. Here is the non_working code.</p>
  
  <pre><code>    String myString;
      List&lt;String&gt; myList;
      var myVariable = Dts.Variables["User::FileNamesList"];
      myList = myVariable as List&lt;String&gt;; //Main Challenge
      myString = myList.Max();
      Dts.Variables.["User::LastFileName"] = myString;
  </code></pre>
  
  <p>Second option I am trying with is to extract into a table object but I still get an error trying to fill the table:   </p>
  
  <pre><code>    OleDbDataAdapter A = new OleDbDataAdapter();
      DataTable dt = new DataTable();
      A.Fill(dt, Dts.Variables["User::pkg_FileList"].Value); //Error
      List&lt;string&gt; myValues = new List&lt;string&gt;();
  </code></pre>