Monday, September 29, 2014

How to use XmlReader.Create

When you initialize fields inline you can only reference static fields. This can lead to unwanted results and you should avoid it. If you need to reference other data, you should do you initialization in the constructor.


As an example or unwanted effects, the code below will result in intField3 being 3 and not 6 as order does matter when using static fields with inline initialization:



public class Class
{
private static int intField2 = intField;
private static int intField = 3;
private int intField3;

public Class()
{
intField3 = intField2 + intField;
}
}


No comments:

Post a Comment