quick question really: I have this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hovel {
public abstract class DamageType {
public string GetKillString(string instigatorName, string victimName) {
return killString.Replace("<inst>", instigatorName).Replace("<vict>", victimName);
}
protected string killString = "ERROR_NO_KILLSTRING_DEFINED";
public string GetDamageString(string instigatorName, string victimName) {
return damageString.Replace("<inst>", instigatorName).Replace("<vict>", victimName);
}
protected string damageString = "ERROR_NO_DAMAGESTRING_DEFINED";
}
public class DamageType_Default : DamageType {
killString = "ERROR_DEFAULT_DAMAGE_TYPE";
damageString = "ERROR_DEFAULT_DAMAGE_TYPE";
}
}
To me, that looks fine, but I get this error for the only two lines in DamageType_Default:
Invalid token '=' in class, struct, or interface member declaration
So… What the?
The problem is the following lines
These lines occur inside a class definition at the scope reserved for members definitions but are instead normal code statements. You’ll need to put these in a method (perhaps a constructor)