I've found a few related questions in Java, but none for C#, so please forgive any duplicates.
Short and sweet, whats the difference? Is there any?
public static class Foo
{
public static List<Bar> Bars;
static Foo()
{
Bars = new List<Bar>();
}
}
public static class Foo
{
public static List<Bar> Bars = new List<Bar>();
}
See the comment by @Nick G for the answer to the case of non-static classes. I'd still like to know if it affects static classes any differently.
Now they don't have to be static either. What about this case?
public class Foo
{
public List<Bar> Bars;
public Foo()
{
Bars = new List<Bar>();
}
}
public class Foo
{
public List<Bar> Bars = new List<Bar>();
}