Include the Namespace System.Xml.Serialization and adding the attribute [XmlIgnore] over the field or property that you want to be excluded in Serialization.
Modifying the Above code it would look like this:
public class TestClass
{
[XmlIgnore]
public int TestVariable
{
get;
set;
}
public int ControlVariable
{
get;
set;
}
public TestClass()
{
TestVariable = 1000;
ControlVariable = 9999;
}
}
This will cause TestVariable to be completely excluded from the serialization.