Is it better to use structs over classes for serializing class settings?

Class settings can have initial default values.

[Serializable]
    public class LevelSettings
    {
        // Default level values
        public int Depth = 3;
        public int Height = 3;
        public TileSettings[] TileSettings = new TileSettings[27];
        public int[] TriangleIndices = new int[0];
        public Vector3[] TriangleVertices = new Vector3[0];
        public float TileSize = 1;
        public int Width = 3;
    }

Structs will take up less memory (and load faster?) but I can't have default settings already set:

[Serializable]
    public struct LevelSettings
    {
        // Default level values
        public int Depth;
        public int Height;
        public TileSettings[] TileSettings;
        public int[] TriangleIndices;
        public Vector3[] TriangleVertices;
        public float TileSize;
        public int Width;

        public LevelSettings(int depth, int height, TileSettings[] tileSettings, int[] triangleIndices, Vector3[] triangleVertices, float tileSize, int width)
        {
            Depth = depth;
            Height = height;
            TileSettings = tileSettings;
            TriangleIndices = triangleIndices;
            TriangleVertices = triangleVertices;
            TileSize = tileSize;
            Width = width;
        }
    }

So umm, thoughts anyone?

Struct are value types and passed by value by default.
Classes are reference types and passed by reference.

This is the only fundamental difference between the two formats.
As far as I am aware there is no difference in the memory consumed by a class or struct with the same fields.
There is very little point in using structs for anything of any real size unless you are performing data manipulation on unmanaged memory.

The example you give is better done as a class as it contains arrays which are a reference type.
Consider the following types

[Serializable]
public struct TestStruct
{
	// Default level values
	public int Value;
	public int[] ArrayData;

	public TestStruct(int value, int[] arrayData)
	{
		Value = value;
		ArrayData = arrayData;
	}
}

[Serializable]
public class TestClass
{
	// Default level values
	public int Value = 3;
	public int[] ArrayData = new int[10];
}

When used they perform differently.

private void button2_Click(object sender, System.EventArgs e)
{
	// make two classes with same values 
	TestClass testClass = new TestClass();
	TestStruct testStruct = new TestStruct(3, new int[10]);

	// copy the class to a new variable
	var newTestClass = testClass;
	// change the value of a property on the new variable
	newTestClass.Value = testClass.Value + 20;
	// test if the values are the same
	if (testClass.Value == newTestClass.Value)
		MessageBox.Show("Class values MATCH");
	else
		MessageBox.Show("Class values DO NOT match");

	// copy the struct to a new variable
	var newTestStruct = testStruct;
	// change the value of a property on the new variable
	newTestStruct.Value = testStruct.Value + 20;
	// test if the values are the same
	if (testStruct.Value == newTestStruct.Value)
		MessageBox.Show("Struct values MATCH");
	else
		MessageBox.Show("Struct values DO NOT match");

	// now lets test the value of one of the array elements

	// change the value of a the first element on each of the four variables 
	testClass.ArrayData[0] = 10;
	newTestClass.ArrayData[0] = 20;
	testStruct.ArrayData[0] = 30;
	newTestStruct.ArrayData[0] = 40;

	// display the values of these
	var sb = new StringBuilder();
	sb.AppendLine("Array test values");
	sb.Append("Original class:");
	sb.AppendLine(testClass.ArrayData[0].ToString());
	sb.Append("New class:");
	sb.AppendLine(newTestClass.ArrayData[0].ToString());
	sb.Append("Original struct:");
	sb.AppendLine(testStruct.ArrayData[0].ToString());
	sb.Append("New struct:");
	sb.AppendLine(newTestStruct.ArrayData[0].ToString());
	MessageBox.Show(sb.ToString());
}
commented: Very clear answer. +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.