Example #1
0
        public static void ByValue(MutableStruct value)
        {
            // A copy of the MutableStruct value has been created

            // this is allowed. I am modifying the copy
            value.DecimalProperty1 = 10;
        }
 public static void Main(string[] args)
 {
     MutableStruct? b = new MutableStruct();
     Console.WriteLine(b.Value.Value);
     b.Value.Increment();
     Console.WriteLine(b.Value.Value);
 }
Example #3
0
        public static void ByRef(ref MutableStruct reference)
        {
            // Value is passed by reference.

            // This change will reflect in the calling code
            reference.DecimalProperty1 = 100;
        }
        public void MutableTest()
        {
            var mutableStruct = new MutableStruct();

            for (var i = 0; i < 100; i++)
            {
                ref readonly MutableStruct immutableReferenceToMutableStruct = ref ReturnImmutableReference(in mutableStruct); //A copy will happen here reducing performance alot. Same will happen with readonly fields: https://codeblog.jonskeet.uk/2014/07/16/micro-optimization-the-surprising-inefficiency-of-readonly-fields/
    static void Main()
    {
        var list = new List <MutableStruct>()
        {
            new MutableStruct {
                Value = 10
            }
        };

        Console.WriteLine("With loop variable capture");
        foreach (MutableStruct item in list)
        {
            Console.WriteLine("Before: {0}", item.Value);
            item.AssignValue(30);
            Console.WriteLine("After: {0}", item.Value);
        }
        // Reset...
        list[0] = new MutableStruct {
            Value = 10
        };

        Console.WriteLine("With loop variable capture");
        foreach (MutableStruct item in list)
        {
            Action capture = () => Console.WriteLine(item.Value);
            Console.WriteLine("Before: {0}", item.Value);
            item.AssignValue(30);
            Console.WriteLine("After: {0}", item.Value);
        }
    }
    public static void Main(string[] args)
    {
        MutableStruct?b = new MutableStruct();

        Console.WriteLine(b.Value.Value);
        b.Value.Increment();
        Console.WriteLine(b.Value.Value);
    }
Example #7
0
    public void SetMutableAndUpdate()
    {
        // Here we test of JSIL.CloneParameter for nullable struct with null and not null value.
        MutableStruct?mutable = new MutableStruct?();

        ProcessUpdate(ref _mutable, ref mutable);
        mutable = new MutableStruct();
        ProcessUpdate(ref _mutable, ref mutable);
        mutable.Value.Increment();
    }
Example #8
0
    static void Main(string[] args)
    {
        var testStruct = new MutableStruct();

        testStruct.EvilInt = 1;
        int test = 1;

        Increment(test, testStruct);
        Console.WriteLine("After increment: " + test + " and..." + testStruct.EvilInt);    //both 1
    }
    static void Main()
    {
        MutableStruct x = new MutableStruct();

        Console.WriteLine(x.value);     // 0
        x.Mutate();
        Console.WriteLine(x.value);     // 1
        x.CallMutate();
        Console.WriteLine(x.value);     // 1
    }
Example #10
0
        static void Main(string[] args)
        {
            Span <MutableStruct> spanOfStructs = new MutableStruct[1];

            spanOfStructs[0].Value = 42;
            Debug.Assert(42 == spanOfStructs[0].Value);
            var listOfStructs = new List <MutableStruct> {
                new MutableStruct()
            };
            //listOfStructs[0].Value = 42; // Error CS1612: the return value is not a variable
        }
Example #11
0
        public static void Test4()
        {
            Span <MutableStruct> spanOfStructs = new MutableStruct[1];

            spanOfStructs[0].Value = 42;

            Console.WriteLine(spanOfStructs[0].Value);

            var listOfStructs = new List <MutableStruct> {
                new MutableStruct()
            };
            //listOfStructs[0].Value = 42;
        }
 public Closure(MutableStruct item)
 {
     Item = item;
 }
Example #13
0
 public SizeInfo(MutableStruct mutableStruct)
 {
     this.str = mutableStruct;
     _size    = mutableStruct.definition.size;
 }
Example #14
0
 public abstract List <Exception> compare(MutableStruct a, MutableStruct b);
Example #15
0
 public void setProperty(MutableStruct value)
 {
     _Property = value;
 }
Example #16
0
 public static void ChangeByRef(ref MutableStruct foo)
 {
     foo = new MutableStruct {
         x = 10
     };
 }
Example #17
0
 static void Increment(int test, MutableStruct test2)
 {
     test2.EvilInt += 1;
     test          += 1;
     Console.WriteLine(test + " and..." + test2.EvilInt);    //both 2
 }