Visit our site: Vist and Get Free Gifts

Learn To Build: Value And Reference Types in C#

Visit our site: Vist and Get Free Gifts

Visit our site: Vist and Get Free Gifts

Tuesday, February 4, 2014

Value And Reference Types in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValAndRefTypes
{
    public class Point
    {
        public int x;
        public int y;
    }

    class Program
    {
        static void testFunc1(int arg1)
        {
            arg1 += 10;
            Console.WriteLine("arg1 is {0}", arg1);
        }

        static void testFunc2(Point pt)
        {
            Console.WriteLine("pt.x is {0}", pt.x);
            pt.x += 10;
            Console.WriteLine("pt.x is {0}", pt.x);
        }

        static void Main(string[] args)
        {
            var i = 10;

            testFunc1(i);
            Console.WriteLine("i is {0}", i);
            Console.WriteLine();

            Point p = new Point();
            p.x = 10;
            p.y = 10;
            Console.WriteLine("p.x is {0}", p.x);
            testFunc2(p);
            Console.WriteLine("p.x is {0}", p.x);

            Console.ReadLine();
        }
    }
}

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home