Possible Duplicate:
Best Practice: Initialize class fields in constructor or at declaration?
Is there any difference between these two classes?
public class Test
{
public Guid objectId = Guid.NewGuid();
}
public class Test2
{
public Guid objectId;
public Test2()
{
objectId = Guid.NewGuid();
}
}
I'm curious if there is any speed or performance differences between them. Is one method preferred over the other? Personally I like the first better because it uses less lines but unless they are virtually identical as far as execution that is a poor reason to choose one over the other.