c# - Why must a static constructor be parameterless? -


i'm encountering error:

'lnkscript.lnkscript.killstreakhud.killstreakhud(infinityscript.entity)': static constructor must parameterless c:\users\home\desktop\lnkscripts.cs 61 20 lnkscript

my source code:

public class killstreakhud : basescript {    static killstreakhud(entity player)    {       string killstreak = "^3killstreak:^3" + player.getfield<int>("killstreak").tostring();       hudelem hudelem = hudelem.createfontstring(player, "hudsmall", 1f);       hudelem.setpoint("topcenter", "topcenter");       hudelem.settext(killstreak);       base.oninterval(300, delegate       {          killstreak = "^3killstreak:^3" + player.getfield<int>("killstreak").tostring();          hudelem.settext(killstreak);          return true;       });    } } 

clearly, static constructor not parameterless, , compiler takes umbrage @ fact. why?

a static constructor must parameterless because nothing ever calls it, invoked when access static member or create instance of class, not directly (it called runtime).

the solution: remove parameters, or make non-static

reference static constructors: http://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx

to make non-static (note need invoked directly new keyword now):

public killstreakhud(entity player) {    ... } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -