static readonly field initializer vs static constructor initialization
- by stackoverflowuser
Below are 2 different ways to initialize static readonly fields. Is there a difference between the 2 approaches? If yes, when should one be preferred over the other?
class A
{
private static readonly string connectionString = WebConfigurationManager.ConnectionStrings["SomeConnection"].ConnectionString;
}
class B
{
private static readonly string connectionString;
static B()
{
connectionString = WebConfigurationManager.ConnectionStrings["SomeConnection"].ConnectionString;
}
}
Thanks.