1 / 17

C# 程序设计语言课程内容

C# 程序设计语言课程内容. 第一章:概述 第二章: C# 语言的基本原理 第三章: C# 中对象的创建 第四章:面向对象的编程技术 第五章: C# 编程 第六章:编写基于 .NET 的应用 程序 第七章:使用 ADO.NET 访问 数据. 第八章:创建基于 Windows 的应用程序 第九章:在 C# 应用程序中使 用 XML Web Service 第十章:创建 Web 应用程序

brita
Download Presentation

C# 程序设计语言课程内容

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C#程序设计语言课程内容 • 第一章:概述 • 第二章:C# 语言的基本原理 • 第三章:C# 中对象的创建 • 第四章:面向对象的编程技术 • 第五章:C# 编程 • 第六章:编写基于 .NET 的应用 程序 • 第七章:使用 ADO.NET 访问 数据 • 第八章:创建基于 Windows 的应用程序 • 第九章:在 C# 应用程序中使 用 XML Web Service • 第十章:创建 Web 应用程序 • 十一章:应用程序设置和 部署 • 十二章:进阶学习目标

  2. 6 编写基于 .NET 的应用 内容: • .NET 框架类库 • 重载 System.Object 的方法 • 格式化字符串和数字 • 使用流和文件 C#

  3. .NET 框架类库 6.1 • .NET 框架类库 • 对象浏览器 • 课堂练习 对象浏览器的使用

  4. System System.Data System.Drawing System.Windows.Forms System.Web.Services System.Web.UI System.Collections System.Diagnostics System.IO .NET 框架类库 • 在 .NET 框架类库中的类是通过一个命名空间层次结构来进行组织管理的 • 常见命名空间

  5. 对象浏览器 6.1.2 浏览 自定义 工具栏 成员窗格 对象窗格 描述窗格

  6. 重载 System.Object 的方法 • 继承自 System.Object 的方法 • 重载和实现 ToString • 课堂练习 重载 ToString 方法

  7. 继承自 System.Object 的方法 • ToString 可以创建并返回一个字符串,该字符串是对相应类实例的描述 • GetHashCode 可以返回相应对象的整数哈希代码 • Equals 判断两个对象是否相同 • GetType 获得当前实例的类型

  8. 重载 ToString 以提供更强的功能 重载和实现 ToString • 继承的 ToString() 返回的类的名字 public enum CarSize { Large, Medium, Small, } public class Car { public CarType Size; } Car myCar = new Car(); myCar.Size = CarSize.Small; MessageBox.Show(myCar.ToString()); WindowsApplication1.Form1.Car public override string ToString() { return ( this.Size.ToString() + " Car"); } Small Car

  9. 格式化字符串和数字 • 格式化数字 • 格式化日期和时间 • 动态字符串 • 课堂练习 格式化字符串

  10. 格式化数字 • 一些 .NET Framework 类使用格式化字符串以返回常见数字串类型,包括以下方法: • String.Format、ToString、Console.WriteLine • String.Format 示例 • {0:c} 格式化信息,其中“0” 是紧随其后的对象的索引,“:c” 说明输出使用货币格式 • 输出是 $12,345.67 (on a US English computer) string s = String.Format( "{0:c}", 12345.67 );

  11. 格式化日期和时间 • DateTimeFormatInfo 类 • 用以格式化 DateTime 对象 输出字符串:Wednesday, March 20, 2002 10:30 AM • 自定义格式字符串 输出字符串:20 Mar 2002 - 10:30:00 System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("f")); System.DateTime dt = new System.DateTime(2002,3,20,10,30,0); MessageBox.Show(dt.ToString("dd MMM yyyy - hh:mm:ss"));

  12. 动态字符串 • 问题:执行下列代码以后,我们怎样能够保留足够的内存? • 答案:使用 StringBuilder 类 for (int i=0; i < 1000; i++) { s = s.Concat(s, i.ToString()); } StringBuilder s = new StringBuilder(); for (int i=0; i < 1000; i++) { s.Append(i); }

  13. 使用流和文件 • 文件 I/O • 读写文本文件 • 读写二进制文件 • 遍历 Windows 文件系统 • 课堂练习 使用文件系统信息

  14. 文件 I/O • 文件是存储在硬盘上的数据集,它具有名称和相应的路径 • 流是可以进行读写操作的东西 • FileAccess 枚举类型 • Read、ReadWrite、Write • FileShare 枚举类型 • Inheritable、None、Read、ReadWrite、Write • FileMode 枚举类型 • Append、Create、CreateNew、OpenOpenOrCreate、 Truncate

  15. 示例 StreamReader StreamReader sr = new StreamReader(@"C:\SETUP.LOG"); textBox1.Text = sr.ReadToEnd(); sr.Close(); StreamWriter StreamWriter sw = new StreamWriter(@"C:\TEST.LOG",false); sw.WriteLine("Log Line 1"); sw.WriteLine("Log Line 2"); sr.Close(); XmlTextReader public class XmlTextReader : XmlReader, IXmlLineInfo XmlTextWriter w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "x", null, "urn:1"); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteStartElement("item","urn:1"); w.WriteEndElement(); w.WriteEndElement(); 读写文本文件

  16. 读写二进制文件 • BinaryReader • 把原始数据类型的数据(二进制形式)读取为具有特定编码格式的二进制数据 • BinaryWriter • 把原始数据类型的数据写入流中,并且它还可以写入具有特定编码格式的字符串 FileStream fs = new FileStream(@"C:\TEST2.DAT",FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fs); w.Write((byte)65); w.Write((byte)66); w.Close(); fs.Close();

  17. 遍历 Windows 文件系统 • 使用 DirectoryInfo 类和 FileInfo 类 • 使用递归 • 函数可以重复调用其自身的编程技术,在每次调用函数时,函数传入的参数是不同的 DirectoryInfo d = new DirectoryInfo("C:\\"); DirectoryInfo[] subd = d.GetDirectories(); foreach (DirectoryInfo dd in subd) { if (dd.Attributes==FileAttributes.Directory) { FileInfo[] f = dd.GetFiles(); foreach (FileInfo fi in f) { listBox1.Items.Add(fi.ToString()); } } }

More Related