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); }
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); }
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(); }
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 }
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 }
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; }
public SizeInfo(MutableStruct mutableStruct) { this.str = mutableStruct; _size = mutableStruct.definition.size; }
public abstract List <Exception> compare(MutableStruct a, MutableStruct b);
public void setProperty(MutableStruct value) { _Property = value; }
public static void ChangeByRef(ref MutableStruct foo) { foo = new MutableStruct { x = 10 }; }
static void Increment(int test, MutableStruct test2) { test2.EvilInt += 1; test += 1; Console.WriteLine(test + " and..." + test2.EvilInt); //both 2 }