Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //By reference and by value

            //syntatic sugar  --> C# does complex things for you behind the scenes that are actually quite complicated
            //C# likes to do things implicitly for you.  Which is nice, but makes us lazy and dummer sometimes :)  :(
            int number = 1;

            PassIntByValFunction(number);  //just remember that integer is not a reference type... so special magic here...
            //Console.WriteLine(number);  //will this show 1 or 6?


            string str = "Brian";        //object... which uses a reference type to point to the actual object

            PassStringByRefFuncion(str); //C# handles strings live Value types (even though they actually are reference types).
            Console.WriteLine(str);      //


            MyTestObj testObj = new MyTestObj();   //pure object

            testObj.MyString = "brian";
            Console.WriteLine(testObj.MyString);
            PassMyTestObjFuncion(testObj);       //there's no return from this function.  It is void!
            Console.WriteLine(testObj.MyString); //

            Console.ReadKey();
        }
Exemplo n.º 2
0
 public static void PassMyTestObjFuncion(MyTestObj testObj) //by default, functions use pass by value (which makes a copy..)
 {
     testObj.MyString = "Stephanie";                        //changing what the pointer is pointing to.
 }