C#语言中类的构造函数详解
来源:互联网 发布:cdr软件图标 编辑:程序博客网 时间:2024/05/24 04:30
原文地址:C#语言中类的构造函数详解作者:摆渡者
默认构造函数
数据类型
默认值
boolfalsebyte0char‘’decimal0.0Mdouble0.0Menum枚举值组合的第一个值float0.0Fint0long0Lsbyte0short0struct将所有的值类型字段设置为默认值,将所有的引用类型字段设置为null时产生的值uint0ulong0ushort0
1: public class Student
2: {
3: private string name;
4: public string Name
5: {
6: get { return this.name; }
7: set { this.name = value; }
8: }
9:
10: private int age;
11: public int Age
12: {
13: get { return this.age; }
14: set { this.age = value; }
15: }
16:
17: public Student(string name, int age)
18: {
19: this.name = name;
20: this.age = age;
21: }
22: }
1: class Program
2: {
3: static void Main()
4: {
5: Student stu = new Student();
6: }
7: }
1: public Student() {}
构造函数在类内部的调用
1: public class Student
2: {
3: private string name;
4: public string Name
5: {
6: get { return this.name; }
7: set { this.name = value; }
8: }
9:
10: private int age;
11: public int Age
12: {
13: get { return this.age; }
14: set { this.age = value; }
15: }
16:
17: private string grade;
18: public string Grade
19: {
20: get { return this.grade; }
21: set { this.grade = value; }
22: }
23:
24: public Student()
25: {
26: Console.WriteLine("一个学生对象被实例化");
27: }
28:
29: public Student(string name, int age)
30: : this()
31: {
32: this
阅读全文
0 0
- C#语言中类的构造函数详解
- c#语言基础(3)----类的构造函数
- C#中构造函数
- C#类的继承中,构造函数的执行顺序
- c# 关于继承类中构造函数的实现
- C#中静态构造函数的学习
- C#中静态构造函数的学习
- C#中静态构造函数的学习
- C#中静态构造函数的学习
- C#中静态构造函数的学习
- C#中构造函数的找错机制
- C#中构造函数的定义
- C#中构造函数的作用
- C#中构造函数的使用
- C#中构造函数的作用
- C#中构造函数的作用
- C#的构造函数
- C#的构造函数
- C#中用“*”打印出菱形
- C#中输出乘法口诀表
- c++计算程序时间
- 猜数字游戏 猜出1-100随机数
- C#中Math类常用函数
- C#语言中类的构造函数详解
- C#输出心形图案(一)
- C#输出心形图案(二)
- POJ3528最大化最小值+三维凸包
- dpkg相关知识
- C++判断文件和文件夹
- 1046:阶乘和数
- CENTOS下firefox看视频缺少flash插件
- Gtk实现GUI键盘并终端显示