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
staticfield inside a struct but not anon-staticfield? - Why do we have to initialize
non-staticin methods bodies?