title: Assign result of a method to a variable in ssis script task using c#
body: <p>I am using vs 2017 ssdt and would like to assign the result of a method to a variable in script task using C#. I am trying to do this outside of main method. I can read the SSIS variable values in the main method using dts variables but not being able to access it outside of the main method.</p>
  
  <pre><code>public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  {
          public void Main()
      {
            //Do something
          }
  
          private class DifferentClass
          {
           private Microsoft.SqlServer.Dts.Runtime.Variables DtsVariables;
           public string MakeURL()
           {
            return DtsVariables["User::URLBase"].Value.ToString() + "/default.aspx"; // how to assign this value to the below variable
           }
  
           string urlbase = MakeURL(); //Return results of MakeURL() to the string urlbase
          }
  }
  </code></pre>
  
  <p>To explain my problem better if I were to access dts variables outside main() method I get error: An object reference is required for the non-static field, method, or property 'VSTARTScriptObjectModelBase.Dts'.</p>
  
  <pre><code>public void Main()
  {
  string test = Dts.Variables["User::TestString"].Value.ToString(); //This works
  }
  
  private class Test
  {
  string newtest = Dts.Variables["User::TestString"].Value.ToString(); //Error: An object reference is required for the non-static field, method, or property 'VSTARTScriptObjectModelBase.Dts'   
  }
  </code></pre>