private void DemoStruct() { //instanciate - we can declare the variable like a standard data type Vector3 v1; v1.x = 3.5f; v1.y = 5.67f; v1.z = 12.1f; //or we can use a constructor TestStruct t1 = new TestStruct(); t1.X = 3.5f; t1.Y = 4.67f; //so how big is this struct? DummyUselessStruct dummy1 = new DummyUselessStruct(); Console.WriteLine("DummyUselessStruct is " + Marshal.SizeOf(dummy1) + " bytes"); //now how big is the struct? did re-organisation change it? DummyUselessStructPacked dummy2 = new DummyUselessStructPacked(); //lets play around with String.Format() - https://dzone.com/articles/java-string-format-examples Console.WriteLine(String.Format("DummyUselessStructPacked is {0} bytes", Marshal.SizeOf(dummy2))); }
/* * Value-types: * - char, byte, bool, int, float, short, long, double, struct(*) * Reference-types: * - array, Vector, List, Student, Person, Player * */ //structs are treated as VALUE types public void Process(DummyUselessStruct theDummy) { theDummy.a = 125; }