C#-Struct简单的用法
来源:互联网 发布:学python还要学hadoop 编辑:程序博客网 时间:2024/06/10 00:17
/*定义Point 里面就只有2个属性 但是我们实际上根本不需要类的全部功能 */
class Point { public int x; public int y; }
这样写就方便多了
struct Point { public int x; public int y; public int X { get { return this.x; } set { this.x = value; } } public Point(int x, int y) { //必须把结构中的变量初始化 this.x = x; this.y = y; } };
Point point1 = new Point(10,20); //第二种方式 Point point2; point2.x = 10; point2.y = 20;
注意事项
1.结构体没有无参数构造方法 必须得提供一个有参数的构造函数初始化字段
2.使用new关键字创建结构对象,并且调用构造方法 但是结构也可以不使用new关键字
如果不使用new关键字 则结构体的字段都是保持未初始化 初始值为0
3.结构不能继承结构或继承类,所有结构继承System.ValueType[隐士继承]后者继承System.Object
4.可以实现接口
5.声明的时候不能初始化结构字段
6.结构是值类型 不是引用类型 例如A复制B结构 只是复制数据 没有复制引用
如果当做参数传递最好前面加引用符号ref
1 0
- C#-Struct简单的用法
- C++--struct的用法
- struct 结构体的用法简单介绍
- C/C++中typedef struct和struct的用法
- C/C++中typedef struct和struct的用法
- C/C++中typedef struct和struct的用法
- C中结构体struct的用法
- c语言struct用法
- C struct的字节对齐问题及sizeof的用法
- C语言中的struct用法
- c/c++ struct的大小以及sizeof用法
- typedef struct 在C和C++中用法的区别
- typedef struct的用法
- typedef struct的用法
- struct stat 的用法
- struct stat 的用法
- struct 用法的示例
- struct的用法
- 关于python中带下划线的变量和函数 的意义
- 思路很简单系列 不过带坑【水水水】
- 集合框架(Map集合/双列集合)
- python中的赋值
- Spring中的@Transactional深度分析之二
- C#-Struct简单的用法
- 结构-01. 有理数比较(10)
- mysql Error 1040 too many connection解决办法
- Handler, MessageQueue, Runnable与Looper
- hdoj1000
- jsp基础知识
- Digital Roots 思路简单 【水】
- Powerdesigner中如何生成测试数据
- python中的高等函数初探