Example #1
0
        /// <summary>
        /// I see no reason why 'in' parameter would ever be used like this
        /// Normal ref is pass by value, so assigning it a new value does not impact original reference
        /// </summary>
        ///
        public @in()
        {
            Console.WriteLine("Test of the keyword: in");
            parameterObject o = new parameterObject(1);

            method2(in o);
            Console.WriteLine("\t" + o.Value);
        }
Example #2
0
        public @ref()
        {
            Console.WriteLine("Test of keyword: ref");

            parameterObject o = new parameterObject(1);

            Console.WriteLine("\tValue = " + o.Value);
            newObject(ref o);
            Console.WriteLine("\tValue = " + o.Value);
        }
        //C# default is pass by value
        public PassByValue()
        {
            Console.WriteLine("Test of Pass by value");

            parameterObject o = new parameterObject(1);

            Console.WriteLine("\tValue = " + o.Value);
            newObject(o);
            Console.WriteLine("\tValue = " + o.Value);
            changeObject(o);
            Console.WriteLine("\tValue = " + o.Value);
        }
 private void changeObject(parameterObject o)
 {
     //this does impact the original reference
     //this is another reference to the same object, now we change the object and not the reference
     o.Value = 2;
 }
 private void newObject(parameterObject o)
 {
     //this dos NOT impact the original reference
     //this is a copy of the reference
     o = new parameterObject(2);
 }
Example #6
0
 private void newObject(ref parameterObject o)
 {
     //this dos impact the original reference, cuz this is the origal ref
     o = new parameterObject(2);
 }
Example #7
0
 private void method(out parameterObject o)
 {
     o = new parameterObject(2);  //must assign it
 }