CSharp - Value types vs reference types
2013-06-03 04:12
295 查看
/*
Author: Jiangong SUN
*/
Results:
References:
http://csharp-station.com/Tutorial/CSharp/Lesson22
Author: Jiangong SUN
*/
public class CompareValueTypeAndReferenceType { public class ReferenceClass { public string Value { get; set; } } public struct Structure { public string Value { get; set; } } public static void Main() { ReferenceClass ref1 = new ReferenceClass(); ref1.Value = "ref1"; ReferenceClass ref2 = new ReferenceClass(); ref2.Value = "ref2"; ref2 = ref1; Console.WriteLine(ref1.Value); Console.WriteLine(ref2.Value); ref2.Value = "ref3"; Console.WriteLine(ref1.Value); Console.WriteLine(ref2.Value); Structure struct1 = new Structure(); struct1.Value = "struct1"; Structure struct2 = new Structure(); struct2.Value = "struct2"; struct2 = struct1; Console.WriteLine(struct1.Value); Console.WriteLine(struct2.Value); struct2.Value = "struct3"; Console.WriteLine(struct1.Value); Console.WriteLine(struct2.Value); Console.ReadLine(); } }
Results:
References:
http://csharp-station.com/Tutorial/CSharp/Lesson22
相关文章推荐
- C# Concepts: Value vs Reference Types - Joseph Albahari
- C# Concepts: Value vs Reference Types - Joseph Albahari
- C# Concepts: Value vs Reference Types
- C# Concepts: Value vs Reference Types
- [C#] C# Concepts: Value vs Reference Types
- Effective C# Item 6: Distinguish Between Value Types and Reference Types
- Item 18: Distinguish Between Value Types and Reference Types(Effective C#)
- parameters vs. arguments and call by value vs. call by reference
- Call by value VS. Call by reference.
- Value Type vs. Reference Type
- Primitive, Reference, and Value Types(Chapter 5 of CLR via C#)
- 【转载】#402 - Value Equality vs. Reference Equality
- 易混问题总结---(by value VS by reference)
- How to Map Distinct Value Types Using Java Generics--reference
- Distinguish Between Value Types and Reference Types - Effective C#学习笔记(6)
- Item 6: Distinguish Between Value Types and Reference Types
- Type Fundamentals (.NET: Primitive types, reference types and value types )
- CLR via C# 总结之Chap5 Primitive, Reference, and Value Types
- Value Type VS Reference Type
- CLR Via C# 3rd 阅读摘要 -- Chapter 5 - Primitive, Reference, and Value Types