c#中,struct和class的区别
2006-06-22 07:23
537 查看
1、struct不允许显示声明其无参数构造函数,这不同于class
2、struct不允许声明时,初始化其数据成员值
3、struct作为参数传递时,可考虑使用ref,以优化性能:因为是值类型(但要注意其值的改变)
4、struct无继承,但其本身继承自System.ValueType ----> System.Object
5、struct可看作是缩小的class,适宜小数据成员时使用
6、理解如下代码:
class Class1
public struct Dimensions
{
public double length;
public double width;
public override string ToString()
{
return this.length + " : " + this.width;
}
}
2、struct不允许声明时,初始化其数据成员值
3、struct作为参数传递时,可考虑使用ref,以优化性能:因为是值类型(但要注意其值的改变)
4、struct无继承,但其本身继承自System.ValueType ----> System.Object
5、struct可看作是缩小的class,适宜小数据成员时使用
6、理解如下代码:
class Class1
public struct Dimensions
{
public double length;
public double width;
public override string ToString()
{
return this.length + " : " + this.width;
}
}
相关文章推荐
- C#中struct与class的区别
- [C#]class 与 struct 的区别
- c#中struct和class的区别
- c#中struct和class的区别
- c#中Class和Struct使用与性能的区别
- C#详解struct和class的区别
- C# 中 Struct 与 Class 的区别,以及两者的适用场合(转载)
- C#详解struct和class的区别
- C#中Struct与Class的区别
- C#中class与struct的区别[转]
- c#中struct和class的区别
- C#中Struct与Class的区别
- C#中struct与class的区别
- C# 中 Struct 与 Class 的区别,以及两者的适用场合
- C#中struct与class的区别
- c#中struct和class的区别
- C#中Struct与Class的区别
- C#中class与struct的区别
- C# struct class 在Marshal.SizeOf 的区别
- C#中Struct与Class的区别