Consider this code block:
struct Animal
{
public string name = ""; // Error
public static int weight = 20; // OK
// initialize the non-static field here
public void FuncToInitializeName()
{
name = ""; // Now correct
}
}
- Why can we initialize a
static
field inside a struct but not anon-static
field? - Why we have initialize
non-static
in methods bodies?