I have the following code in my class:
public string StrLog {get; set;}
then within the same class, I have the following code:
private string imgData = StrLog;
I get the following error message:
A field initializer cannot reference the non-static field, method or property
It has a problem with:
private string imgData = StrLog;
but not sure how to resolve this.
Basically, you cannot initialise a class level variable by using any other class level value (unless that value is static) – which is what your error is trying to tell you.
Your best option would be to assign the value in your constructor:
In your case there is no point assigning it the value of
StrLogbecauseStrLogwon’t have a value to begin with. So you may as well just assign itnull, or an actual value form somewhere else (like my example)