using System; namespace StructDemonstration { // Declare a struct named Colour public struct Colour { public int red { get; set; } public int green { get; set; } public int blue { get; set; } // constructor public Colour(int rVal, int gVal, int bVal) : this() { red = rVal; green = gVal; blue = bVal; } // Display the Struct as a String public override string ToString() { return (String.Format("{0}, {1}, {2}", red, green, blue)); } } // End struct public class Tester { public void Run() { // Create an instance of the struct Colour colour1 = new Colour(100, 50, 250); // Display the values in the struct Console.WriteLine("colour1 colour: {0}", colour1); // Invoke the default constructor Colour colour2 = new Colour(); Console.WriteLine("colour2 colour: {0}", colour2); // Pass the struct to a method myFunc(colour1); // Redisplay the values in the struct Console.WriteLine("colour1 colour: {0}", colour1); } // Method takes a struct as a parameter public void myFunc(Colour col) { // Modify the values through the properties col.red = 200; col.green = 100; col.blue = 50; Console.WriteLine("colour1 colour: {0}", col); } static void Main() { Tester t = new Tester(); t.Run(); Console.ReadLine(); } } }