C编程分析和总结.docxVIP

  • 0
  • 0
  • 约2.88万字
  • 约 40页
  • 2023-05-12 发布于上海
  • 举报
规划理想职业,成就精彩人生 C# 学习方法 周先群 规划理想职业,成就精彩人生 规划理想职业,成就精彩人生 目录 类的构造器 1 this 的用法 2 Base 的用法 4 类 9 用派生类去实例化基类,到底有什么作用?要用于类型转换 9 接口 10 泛型的接口 11 字符 12 Char 类 12 可变字符 StringBuilder 18 数组 20 声明数组 20 创建数组 20 初始化数组 20 Array 类的属性 22 Array 类的方法 22 ArrayList 集合类 27 ArrayList 构造器 27 ArrayList 集合类的常用属性 27 ArrayList 方法 28 Windows 窗体 29 文件流 31 常用的类 31 BinaryReader 31 BinaryWriter 31 BufferedStream 31 Directory 31 DirectoryInfo 31 DirveInfo 31 EndOfStreamExcption 31 File 32 FileInfo 35 FileStream 35 FileSystemWatcher 35 IOException 35 MemoryStream 35 Path 35 Stream 35 StreamReader 35 StreamWriter 36 StringReader 36 StringWriter 36 TextReader 36 TextWriter 36 FileSysWatcher 36 规划理想职业,成就精彩人生 规划理想职业,成就精彩人生 PAGE PAGE 1 类的构造器 先看两个类定义(构造函数): class A{ } 相当于: class A: object { Public A ( ) : base( ) { } } 在类定义中定义自定义构造函数 ,默认构造函数会被默默地删除; 所以必须为类显式重定义默认构造函数,否则不能使用默认构造函数创建类类型的实例. 看一个代码: -构造器在类实例化的过程中执行. -构造器没有返回值. 类在实例化的时候会对它的成员变量进行初始化; 但在使用局部变量之前必须要赋值. this 关键字作用: 进行自引用; 转发构造函数调用 . this 是个隐含指针, 指向类实例化后的对象本身. 构造器可以有多种重载 规划理想职业,成就精彩人生 规划理想职业,成就精彩人生 2 2 成员变量初始化: C#允许在声明成员变量时对其进行初始化,但这样会产生代码冗余. class A { public int i = 100; public string s = 森林; public A() { } public A(int i) { this.i = i; } public A(string s) { this.s = s; } public A(int i, string s) { this.i = i; this.s = s; } } class A { public int i; public string s; public A() { i=100; s=森林; } public A(int i) : this() //注意this的使用 { this.i = i; } public A(string s) : this() { this.s = s; } public A(int i, string s) : this() { this.i = i; this.s = s; } } this 的用法 this 关键字将引用类的当前实例。静态成员函数没有 this 指针。this 关键字可用于从构造函数、实例方法和实例访问器中访问成员。 限定被相似的名称隐藏的成员 public Employee(string name, string alias) { = name; this.alias = alias; } 将对象作为参数传递到其他方法 在静态方法、静态属性访问器或字段声明的变量初始值设定项中引用 this 是错误的 CalcTax(this); //声明索引器 public int this [int param] { get{return array[param]; } set{array[param] = value; } } 规划理想职业,成就精彩人生 规划理想职业,成就精彩人生 PAGE PAGE 10 在自身的类调传递参数 public class ConstructorP

文档评论(0)

1亿VIP精品文档

相关文档