示例#1
0
        /// <summary>
        /// Function for getting and setting properties from/to a struct.
        /// </summary>
        public void changeProperties()
        {
            StructExample st = new StructExample();

            st.PropVar = 666;
            Console.WriteLine($"propVar is {st.PropVar}");
        }
示例#2
0
        /// <summary>
        /// Function for changing static field a struct.
        /// </summary>
        public void changeStaticFieldInStruct()
        {
            StructExample st = new StructExample();

            //st.staticInt = 500;       compile error. Static fields of structs should be accessed using the name of the struct itself.
            StructExample.staticInt = 1000;
        }
示例#3
0
        /// <summary>
        /// Function for initializing struct with direct access to its parameters.
        /// </summary>
        public void structInitializationWithoutConstructor()
        {
            StructExample st = new StructExample();

            st.parameter1 = 100;
            st.parameter2 = "some string";

            Console.WriteLine($"parameter1 is {st.parameter2} and parameter2 is {st.parameter2}");
        }
示例#4
0
        /// <summary>
        /// Function for initializing struct with parameterized constructor.
        /// </summary>
        public void structInitializationWithConstructor()
        {
            StructExample st = new StructExample(200, "constructor string");

            Console.WriteLine($"parameter1 is {st.parameter2} and parameter2 is {st.parameter2}");
        }