已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2019/8/1,1,高级程序设计,授课教师:祁长兴,C#,第八章:常用类,2019/8/1,2,常用类,2019/8/1,3,Math,静态字段 PI E 静态方法 整数运算 初等函数 三角函数,Abs():求绝对值 Ceiling()求大于等于指定数值的最小整数 Floor ()求小于或等于指定数值的最大整数 Round ()对数值进行四舍五入,Exp():求e的指数幂 Pow()指数函数 Log()对数函数 Lg10 ()求以10为底的对数 Sqrt ()求平方根,Sin():求正弦函数 Cos()求余弦函数 Tan()求正切函数 。,2019/8/1,4,static void Main(string args) double a = -1.2; int k = -1,d; double b,c; int i; b = Math.Abs(a); Console.WriteLine(“Abs(a)=0“, b); d = Math.Abs(k); Console.WriteLine(“Abs(k)=0“, d); c = Math.Ceiling(1.2);,Console.WriteLine(“Ceiling(1.2)=0“, c); c = Math.Floor(1.2); Console.WriteLine(“Floor(1.2)=0“, c); c = Math.Round(1.5); Console.WriteLine(“Round(1.5)=0“, c); c = Math.Round(1.2); Console.WriteLine(“Round(1.2)=0“, c); b = Math.Exp(2.1); Console.WriteLine(“Exp(2.1)=0“, b); b = Math.Pow(2, 3); Console.WriteLine(“Pow(2, 3)=0“, b); b = Math.Log(10); Console.WriteLine(“Log(10)=0“, b); b = Math.Log10(10); Console.WriteLine(“Log10(10)=0“, b); b = Math.Sqrt(9); Console.WriteLine(“Sqrt(9)=0“, b); Console.ReadLine(); ,2019/8/1,5,Math,DemoP8-1,2019/8/1,6,string,构造函数与赋值 1。直接赋值:string s1=“software” 2。构造函数赋值: string(char, int) string(char) string(char, int, int),2019/8/1,7,static void Main(string args) string s1 = “helloworld!“; Console.WriteLine(“s1=0“, s1); string s2 = new string(a, 5); Console.WriteLine(“s2=0“, s2); char s3=new charm,i,c,r,o,s,o,f,t; string s4 = new string(s3); string s5 = new string(s3,1,4); Console.WriteLine(“s3=0“, s3); Console.WriteLine(“s4=0“, s4); Console.WriteLine(“s5=0“, s5); Console.ReadLine(); ,2019/8/1,8,String,获取字符 string char: 索引函数 string char: char ToChayArray() char ToChayArray(int int)/起始位置,复制的长度 CopyTo(int,char,int,int)/起始位置,目标数组,指定数组起始位置,复制的长度,2019/8/1,9,static void Main(string args) string s1 = “Microsoft!“; char chs1 = s1.ToCharArray(); char chs2 = s1.ToCharArray(5, 4); Console.WriteLine(new string(chs1); Console.WriteLine(new string(chs2); char chs = new char20; “Microsoft“.CopyTo(0,chs,0,9); “Windows2003“.CopyTo(0, chs, 10, 7); Console.WriteLine(new string(chs); Console.ReadLine(); ,2019/8/1,10,字符查找,int IndexOf(char) int IndexOf(char,int) int IndexOf(char,int,int) int LastIndexOf(char,int,int) int IndexOfAny(char),static void Main(string args) string s1 = “沈阳师范大学软件学院“; int pos = s1.IndexOf(软); Console.WriteLine(“pos=0“, pos); Console.ReadLine(); ,2019/8/1,11,public class SearchCharSample static void Main() bool bFail = true; string sName; char illChars = , #, $, %, ,2019/8/1,12,练习,输入一个字符串,求其中字符e出现的次数,2019/8/1,13,using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 class Program static void Main(string args) / string s1 = “miscrosoft is a big company and it is super enterprise.I study from it and want to enter“; s1 = Console.ReadLine(); int i = 0, j=0,pos =0; while (pos = 0) pos = s1.IndexOf(e, j); if (pos = 0) i+; j = pos + 1; Console.WriteLine(“i=0“,i); Console.ReadLine(); ,2019/8/1,14,字符串填充与修剪,string PadLeft(int) string PadLeft(int char) string Trim() string Trim(char)/TrimStart(), TrimEnd(),2019/8/1,15,static void Main(string args) string s1=“Microsoft“,s2,s3,s4; s2 = s1.PadLeft(12, ); s3 = s2.PadRight(14, ); s4 = s3.PadLeft(16, *); s4 = s4.PadRight(18, *); Console.WriteLine(“0“,s4); Console.ReadLine(); ,2019/8/1,16,String,获取子串 SubString 查找子串 IndexOf / LastIndexOf StartsWith / EndWith 插入/删除子串 Insert / Remove 替换子串 Replace,2019/8/1,17,练习,输入一个字符串,去掉其中子串err,2019/8/1,18,static void Main(string args) / string s1=“Microsoft is are a big company and the leader in it is are super man! “; s1= Console.ReadLine(); int pos=0; while (pos = 0) pos = s1.IndexOf(“are“); if (pos=0) s1 = s1.Substring(0, pos) + s1.Substring(pos + “are“.Length); Console.WriteLine(“0“, s1); Console.ReadLine(); 问题是? =“Microsoft is are a big company and the leader in it is aarere super man! “;,2019/8/1,19,static void Main(string args) string s1=“Microsoft is are a big company and the leader in it is aarere super man! “,s2; s2 = “; int pos=0; while (pos = 0) pos = s1.IndexOf(“are“); if (pos = 0) s2 =s2+ s1.Substring(0, pos); s1 = s1.Substring(pos + “are“.Length); s2 += s1; Console.WriteLine(“0“, s2); Console.ReadLine(); ,2019/8/1,20,static void Main(string args) string s1=“Microsoft is are a big company and the leader in it is aarere super man! “,s2; s2 = s1.Replace(“are“,“); Console.WriteLine(“0“, s2); Console.ReadLine(); ,2019/8/1,21,Remove() Insert(),2019/8/1,22,String,格式化字符串 Format 解析字符串 Parse / TryParse Demo,2019/8/1,23,StringBuilder,构造函数 性能优化 Demo,2019/8/1,24,常用数据结构类,DateTime: 日期/时间 你会如何设计这个类? ArrayList: 链表 你会如何设计这个类? Demo,2019/8/1,25,String,编写程序,输入一个字符串,求串中包含字符串“am”的个数。,2019/8/1,26,static void Main(string args) string s1 = “iamamiddleschoolstudentndiamaboy!iamateacher“; int j=0,k=0,i=0; while( i=0) i = s1.IndexOf(“am“, k); Console.WriteLine(“i = 0“, i); if( i=0) j+; k=i+“am“.Length; Console.WriteLine(“s1 = 0“, j); Console.ReadLine(); ,2019/8/1,27,String,判断输入的字符串是否为有效身份证号码(18位,第7位开始,连续8个数字为日期即可),2019/8/1,28,class Program static void Main(string args) string s1 = Console.ReadLine(); if (s1.Length != 18) Console.WriteLine(“无T效的?身?份证号?码?“); else string s2 = s1.Substring(6, 8); s2 = s1.Substring(6, 4) + “-“ + s1.Substring(10, 2) + “-“ + s1.Substring(12, 2); try DateTime d1 = DateTime.Parse(s2); Console.WriteLine(“有瓺效的?身?份证号?码?“); catch (Exception) Console.WriteLine(“无T效的?身?份证号?码?“); finally Console.ReadLine(); ,2019/8/1,29,常用类,Windows窗体和控件,2019/8/1,30,Windows窗体和控件,Color Size / Point SizeF / PointF Demo,2019/8/1,31,Windows窗体和控件,Form 构造函数 属性 方法 事件 Demo,2019/8/1,32,Windows窗体和控件,Control 属性 方法 事件,2019/8/1,33,Windows窗体和控件,2019/8/1,34,Windows窗体和控件,模态 ShowDialog 非模态 Show 常用事件 Load FormClosing FormClosed。,2019/8/1,35,Windows窗体和控件,private void Form1_FormClosing(object sender, FormClosingEventArgs e) MessageBox.Show(“Form1_FormClosing“); private void Form1_FormClosed(object sender, FormClosedEventArgs e) Message
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年国家移民管理局直属事业单位公开招聘事业编制人员(16人)模拟试卷带答案解析
- 2025江西萍乡市妇幼保健院招聘编外人员(第二批)17人模拟试卷带答案解析
- 2025北京国专知识产权有限责任公司招聘4人(二)历年真题库带答案解析
- 2025年福建南平武夷有轨电车有限公司社会招聘(五)历年真题汇编带答案解析
- 2025湖口县公开选调殡仪馆事业编制工作人员5人模拟试卷附答案解析
- 2025和田市公安局招聘编制外警务辅助人员(补录)(110人)笔试备考试卷带答案解析
- 2025吉林通化市集安市消防救援大队招聘3人备考公基题库附答案解析
- 2025浙江丽水云和县富云国有资产投资集团有限公司招聘劳务用工4人备考题库带答案解析
- 2025年湖南省中医药研究院招聘13人历年真题汇编附答案解析
- 2026四川大学华西第二医院人才批量招聘骨干医师招生24人参考题库带答案解析
- 加油加气站可行性研究报告
- GB/T 3836.31-2021爆炸性环境第31部分:由防粉尘点燃外壳“t”保护的设备
- 日用百货购销合同标准范本
- GB/T 2423.29-1999电工电子产品环境试验第2部分:试验方法试验U:引出端及整体安装件强度
- GB/T 20666-2006统一螺纹公差
- GB/T 18847-2002聚氯乙烯覆膜金属板
- GB/T 11406-2001工业邻苯二甲酸二辛酯
- 需配备的物业办公物资表
- 洲际酒店员工培训l课件
- 涉电镀工艺企业(园区)安全隐患排查表
- 心愿(任志萍词伍嘉冀曲、吴小平编合唱)合唱谱图片格式-合唱谱
评论
0/150
提交评论