c# - Set static variable to ssis variable - error -


i have static variable -

static readonly string tablename; 

i tried set this

static readonly string tablename = dts.variables["ssisstring"].value.tostring(); 

i error:

an object reference required non-static field, method, or property.  

but, works this:

static string tablename = "";   main() {      tablename = dts.variables["ssisstring"].value.tostring(); } 

why ?

it's not static part, it's readonly hosing you.

enter image description here

    static readonly string tablename;      static scriptmain()     {         // object reference required non-static field, method, or property 'microsoft.sqlserver.dts.tasks.scripttask.vstartscriptobjectmodelbase.dts.get'         tablename = dts.variables["ssisstring"].value.tostring();     }      public void main()     {         // works         string local = dts.variables["ssisstring"].value.tostring();          // static read field cannot assinged (except in static constructor or variable initializer)         tablename = dts.variables["ssisstring"].value.tostring();          dts.taskresult = (int)scriptresults.success;     } 

my poorly remembered information static there 1 instance of variable instantiations of class. since there's going 1 instance of scriptmain, getting going static vs instance variable?

anyways, 1 instance of tablename , want assign value. problem is, thing has value want use has instantiated provide value. isn't problem, demonstrate, when assigned inside main method.

it is problem though because readonly property allows assign value in static constructor or variable initializer... in head gets problem of needing instance.

some .net person, feel free slag on or improve answer using proper terminology.

references


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -