Beispiel #1
0
        static void Main(string[] args)
        {
            // Ref type
            UserRef ref1 = new UserRef {
                FirstName = "First1", LastName = "Last1", ID = 1
            };

            // Copy just the reference for the ref type
            UserRef ref2 = ref1;

            ref2.FirstName = "First changed";
            Console.WriteLine("{0}", UserRef.AreEqual(ref1, ref2)); // true

            ref1 = new UserRef {
                FirstName = "First1", LastName = "Last1", ID = 1
            };
            // Create a shallow copy for the ref type
            ref2           = ref1.ShallowCopy();
            ref2.FirstName = "First changed";
            Console.WriteLine("{0}", UserRef.AreEqual(ref1, ref2)); //false

            // Value type
            UserValue val1 = new UserValue("First", "Last", 1);

            // copy value type
            UserValue val2 = val1;

            val2.LastName = "Changed last name";

            Console.WriteLine("{0}", UserValue.AreEqual(val1, val2)); //false

            Console.ReadKey();
        }
Beispiel #2
0
 public static bool AreEqual(UserRef a, UserRef b)
 {
     return(a.FirstName == b.FirstName && a.LastName == b.LastName && a.ID == b.ID);
 }
Beispiel #3
0
 public UserRef(UserRef another)
 {
     FirstName = another.FirstName;
     LastName  = another.LastName;
     ID        = another.ID;
 }