NET Framework类库_第1页
NET Framework类库_第2页
NET Framework类库_第3页
NET Framework类库_第4页
NET Framework类库_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.NET Framework类库.NET 是微软公司最新推出的软件开发平台,该平台由CLR和.NET类库组成。该类库功能十分完善,可以简化编程工作,在程序中应尽可能采用类库。在程序中使用命名空间时,除了默认导入的命名空间可以直接使用外,其他的命名空间还需要使用using导入之后才能使用。System:包含有许多常用的基本类,是默认导入的命名空间。System.data:包含ADO操作的相关类,是默认导入的命名空间。System.data.oledb:包含OLE DB.NET连接类。非默认导入的命名空间。一、 数学运算类protected void Page_Load(object sender

2、, EventArgs e) Response.Write("<br> abs(-4)的值是:"); Response.Write(Math.Abs(-4); Response.Write("<br> sign(-2.4)的值是:"); Response.Write(Math.Sign(-2.4); Response.Write("<br> max(5,7)的值是:"); Response.Write(Math.Max(5, 7); Response.Write("<br> c

3、eiling(2.4)的值是:"); Response.Write(Math.Ceiling(2.4); Response.Write("<br> floor(-2.8)的值是:"); Response.Write(Math.Floor(-2.8); Response.Write("<br> round(4.5001)的值是:"); Response.Write(Math.Round(4.5001);二、 字符串操作类 protected void Page_Load(object sender, EventArgs e

4、) string stra = "真有趣" string strb = "ASP.NETFHW 真有趣" Response.Write("stra内容为:"); Response.Write(stra + ""); Response.Write("<br>stra的长度为:" + stra.Length.ToString(); Response.Write("<br>net的位置是:"+stra.IndexOf("net").ToS

5、tring(); Response.Write("<br>a串与b串比较的结果为:"+stra.CompareTo(strb).ToString(); Response.Write("<br>a 串与b串是否相等"+stra.Equals(strb).ToString(); 三、 日期、时间类日期、时间类System.DataTime也是属于system命名空间protected void Page_Load(object sender, EventArgs e) DateTime date1 = DateTime.Now; Da

6、teTime date2 = new DateTime(2008, 08, 08, 08, 08, 08, 08); Response.Write("<br>date1.date的值为" + date1.Date.ToString(); Response.Write("<br>date1.year的值为" + date1.Year.ToString(); Response.Write("<br>date1.month的值为" + date1.Month.ToString(); Response.Wr

7、ite("<br>date1.day的值为" + date1.Day.ToString(); Response.Write("<br>date1.timeofday的值为" + date1.TimeOfDay.ToString(); Response.Write("<br>date1.hour的值为" + date1.Hour.ToString(); Response.Write("<br>date1.minute的值为" + date1.Minute.ToStrin

8、g(); Response.Write("<br>date1.second的值为" + date1.Second.ToString(); Response.Write("<br>date1.dayofyear的值为" + date1.DayOfYear.ToString(); Response.Write("<br>date1.dayofweek的值为" + date1.DayOfWeek.ToString(); Response.Write("<br>date2.date的值

9、为" + date2.Date.ToString(); Response.Write("<br>date2.day的值为" + date2.Day.ToString(); Response.Write("<br>date2.dayofyear的值为" + date2.DayOfYear.ToString(); Response.Write("<br>date2.dayofweek的值为" + date2.DayOfWeek.ToString(); Response.Write("

10、<br>DateTime.Today的值为" + DateTime.Today.ToString(); 四、 随机数类protected void Page_Load(object sender, EventArgs e) Random r1 = new Random(); byte r = new byte300; int i = 0; Response.Write("<br>r1.next的结果是:"+r1.Next().ToString(); Response.Write("<br>r1.next(200)的结果

11、是:" + r1.Next(200).ToString(); Response.Write("<br>r1.next(200,250)的结果是:" + r1.Next(200,250).ToString(); Response.Write("<br>r1.nextdouble的结果是:" + r1.NextDouble().ToString(); r1.NextBytes(r); Response.Write("<br>r1.nextbytes(r)操作后r元素的r(299)的结果是:"

12、); Response.Write(r299);五、 文件操作类System.IO命名空间包含有多个类,利用这些类可以实现服务器磁盘中目录、文件的建立、写入、读出、删除等功能,另外还可以对文本文件、二进制文件进行读写操作。完成这些功能都必须利用System.IO命名空间中的相关类才能实现。System.IO 命名空间不是默认导入的命名空间,需要在程序中利用using导入。1、目录管理例:新建WEB窗体,添加如下控件(4_1)。控件ID类型属性ts1labelText:生成新文件夹ts2labelText:删除文件夹Label1labelText:”Label2labelText:”path1t

13、extboxText:”path2textboxText:”createbuttonText:生成deletebuttonText:删除using System;using System.IO;public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) string dr = Directory.GetLogicalDrives(); int i = 0; Label1.Text = "WEB服务器中逻辑驱动器列表:" for

14、(i = 0; i <= dr.Length - 1; i+) Label1.Text = Label1.Text + dri + "&nbsp" protected void create_Click(object sender, System.EventArgs e) if (path1.Text.Trim() != "") if (Directory.Exists(path1.Text) this.Label2.Text = "目录已经存在!" else Directory.CreateDirectory(path

15、1.Text); this.Label2.Text = "目录已经生成" else this.Label2.Text="请输入新目录路径名" protected void delete_Click(object sender, System.EventArgs e)if(path2.Text.Trim()!="") if (Directory.Exists(path1.Text) Directory.Delete(path2.Text); this.Label2.Text = "目录已经删除!" else this

16、.Label2.Text="目录不存在"else this.Label2.Text="请输入目录路径名" 2、文件管理、文件管理主要由System.IO命名空间的Fileinfo类和Filestream类完成。FileInfo类是一个密封类,它可以用来创建、复制、删除、移动和打开文件。Filestream用于对文件进行读写操作。Fileinfo类包含以下几个常用的方法和属性。exists:判断文件是否存在。create:创建文件。Delete:删除文件。例:新建窗体,并添加如下控件(4_2)。ID类型属性ts1labelText:生成新文件ts2labe

17、lText:删除文件label1labelText:”file1textboxText:”file2textboxText:”createbuttonText:生成deletebuttonText:删除using System;using System.IO; protected void create_Click(object sender, EventArgs e) if (file1.Text != "") FileInfo f = new FileInfo(file1.Text); if (f.Exists) Label1.Text = "文件已经存在!" else FileStream fs = f.Create(); fs.Close(); Label1.Text = "文件已经生成!" else Label1.Text = "请输入新文件名(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论