C# class and struct
2015-08-12 14:05
537 查看
"A class or struct definition is like a
blueprint that specifies what the type can do. An
object is basically a block of memory that has been allocated and configured according to the blueprint. A
program may create many objects of the same class. Objects
are also called instances, and they can be stored in either a named variable or in an array or collection. Client
code is the code that uses these variables to call the methods and access the public properties of the object. In
an object-oriented language such as C#, a typical program consists of multiple objects interacting dynamically."
---from Microsoft Developer Network
variable of a class object holds a reference to the address of the object on the managed heap. If
a second object of the same type is assigned to the first object, then both variables refer to the object at that address. This
point is discussed in more detail later in this topic."
holds a copy of the entire object"
blueprint that specifies what the type can do. An
object is basically a block of memory that has been allocated and configured according to the blueprint. A
program may create many objects of the same class. Objects
are also called instances, and they can be stored in either a named variable or in an array or collection. Client
code is the code that uses these variables to call the methods and access the public properties of the object. In
an object-oriented language such as C#, a typical program consists of multiple objects interacting dynamically."
---from Microsoft Developer Network
Class
"Because classes are reference types, avariable of a class object holds a reference to the address of the object on the managed heap. If
a second object of the same type is assigned to the first object, then both variables refer to the object at that address. This
point is discussed in more detail later in this topic."
<span> </span>Country country1 = new Country();
<span> </span>//new object being created using class
<span> </span>
<span> </span>Country country2 =country1;
<span> </span>// assigning country2 to the same reference as country1
<span> </span>// so that country 1 and 2 contain the references to the same address, any change made on country2 results in change on country1
</pre><pre name="code" class="csharp">
struct
"Because structs are value types, a variable of a struct objectholds a copy of the entire object"
<span> </span>Country C1 = new C1();
<span> </span>
<span> </span>Country C2 = C1;
<span> </span>// the whole object of C1 is copied to C2, meaning that there are now two objects(a new object is created)
相关文章推荐
- c#解析XML文件来获得pascal_voc特定目标负样本
- 总结C#保留小数位数
- C#中的委托和事件(续)
- C# 中的委托和事件
- C#实现Ping的方法小结
- C#实现xml文件的读取与写入简单实例
- C#实现将数据导出到word或者Excel中的方法
- C#异步方法的使用
- *****c#中的委托和事件
- C#学习If-else
- C#操作Excel文件
- c#params ref out
- c#params ref out
- C#学习第四天
- C#线程池ThreadPool
- C# DataRow[]转换DataTable
- c#用socket异步传输字符串
- c#用socket异步传输字符串
- c#socket同步通信
- c#socket同步通信