您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 企业财务 > c#控制台学生管理系统
简单的学生管理系统,适合初学者学习。联系人:787069354文件操作类usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Collections;usingSystem.IO;namespacestudent{///summary///文?件t读¨¢写¡ä类¤¨¤////summaryclassflleaccess{privatestaticstringfileName;///summary///静2态¬?属º?性?,ê?获?取¨?或¨°设¦¨¨置?用®?于®¨²存ä?储ä¡é的Ì?文?件t名?。¡ê////summarypublicstaticstringFileName{get{returnfileName;}set{fileName=value;}}#region读¨¢取¨?数ºy据Y///summary///读¨¢取¨?数ºy据Y,ê?以°?行D的Ì?方¤?式º?存ä?入¨?ArrayList中D////summary///returns返¤¦Ì回?填¬?充?好?的Ì?集¡¥合?类¤¨¤/returnspublicstaticArrayListReadData(){ArrayListlist=newArrayList();if(File.Exists(student.txt)&&chekfile()){FileStreamfs=newFileStream(fileName,FileMode.Open,FileAccess.Read);StreamReadersr=newStreamReader(fs,Encoding.Default);stringtemp=null;while((temp=sr.ReadLine())!=null){list.Add(temp);}sr.Close();fs.Close();}returnlist;}#endregion#region写¡ä入¨?数ºy据Y///summary///用®?传ä?入¨?的Ì?集¡¥合?更¨¹新?数ºy据Y////summary///paramname=list已°?经-变À?化¡¥的Ì?集¡¥合?/parampublicstaticvoidWriteData(ArrayListlist){if(chekfile()){FileStreamfs=newFileStream(fileName,FileMode.Create,FileAccess.Write);StreamWritersw=newStreamWriter(fs,Encoding.Default);foreach(stringsinlist){sw.WriteLine(s);}sw.Close();fs.Close();}}#endregion#region检¨¬查¨¦文?件t是º?否¤?符¤?合?标À¨º准Á?///summary///检¨¬查¨¦文?件t是º?否¤?合?法¤¡§////summary///returns/returnsprivatestaticboolchekfile(){boolisValid=true;if(fileName==null||fileName.Equals(string.Empty)){isValid=false;thrownewArgumentNullException(文?件t名?,不?能¨¹为a空?!ê?);}returnisValid;}#endregion}}学生信息类usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacestudent{///summary///学¡ì生¦¨²信?息¡é类¤¨¤////summaryclassstuinfo{privatestringstuNum;//学¡ì号?privatestringstuName;//姓?名?privatestringstuAge;//年¨º龄¢?privatestringstuSex;//性?别ÀeprivatestringstuClass;//所¨´在¨²班㨤级?;publicstringStuNum{get{returnstuNum;}set{stuNum=value;}}publicstringStuName{get{returnstuName;}set{stuName=value;}}publicstringStuAge{get{returnstuAge;}set{stuAge=value;}}publicstringStuSex{get{returnstuSex;}set{stuSex=value;}}publicstringStuClass{get{returnstuClass;}set{stuClass=value;}}publicstuinfo(stringnum,stringname,stringage,stringsex,stringsclass){this.stuNum=num;this.stuName=name;this.stuAge=age;this.stuSex=sex;this.stuClass=sclass;}publicstuinfo(){}#region显?示º?学¡ì生¦¨²信?息¡é///summary///显?示º?学¡ì生¦¨²信?息¡é////summary///returns/returnspublicstringshowstuinfo(){returnstuNum++stuName++stuAge++stuSex++stuClass;}#endregion}}学生操作类usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Collections;namespacestudent{///summary///学¡ì生¦¨²操¨´作Á¡Â类¤¨¤////summaryclassstuopration{privateArrayListarryList=newArrayList();publicstuopration(){flleaccess.FileName=student.txt;ArrayListList=newArrayList();List=flleaccess.ReadData();foreach(stringsinList){stuinfostu=newstuinfo();inti=0;string[]infos=s.Split(newchar[1]{''});stu.StuNum=infos[i];stu.StuName=infos[++i];stu.StuAge=infos[++i];stu.StuSex=infos[++i];stu.StuClass=infos[++i];arryList.Add(stu);}}#region索¡Â引°y器¡Â///summary///索¡Â引°y器¡Â////summary///paramname=indx/param///returns/returnspublicstuinfothis[intindx]{get{if(indx-1&&indxarryList.Count)return(stuinfo)arryList[indx];elsethrownewArgumentOutOfRangeException(索¡Â引°y值¦Ì,索¡Â引°y值¦Ì不?合?法¤¡§!ê?);}set{if(indx-1&&indxarryList.Count)arryList[indx]=value;elseConsole.WriteLine(您¨²输º?入¨?的Ì?数ºy据Y有®D问¨º题¬a);}}#endregion#region添¬¨ª加¨®学¡ì生¦¨²///summary///添¬¨ª加¨®学¡ì生¦¨²////summarypublicvoidaddstu(stuinfostu){arryList.Add(stu);}#endregion#region删¦?除y一°?个?学¡ì生¦¨²///summary///按ã¡ä学¡ì号?删¦?除y////summary///paramname=stu/parampublicvoidRemoveStuNum(stringnum){foreach(stuinfostuinarryList){if(stu.StuNum.Trim()==num.Trim()){arryList.Remove(stu);break;}}}///summary///按ã¡ä姓?名?删¦?除y////summary///paramname=indx/parampublicvoidRemoveStuName(stringname){try{foreach(stuinfostuinarryList){if(stu.StuName.Trim()==name.Trim()){arryList.Remove(stu);}}}catch{Console.WriteLine(数ºy据Y已°?删¦?除y);}}#endregion#region清?空?学¡ì生¦¨²信?息¡é///summary///清?空?数ºy据Y////summarypublicvoidclear(){arryList.Clear();}#endregion#region查¨¦询¡¥学¡ì生¦¨²///summary///查¨¦询¡¥全¨?体¬?学¡ì生¦¨²////summarypublicvoidFindAllStu(){foreach(stuinfostuinarryList){string[]str=(stu.showstuinfo()).Split(newchar[1]{''});Console.WriteLine({0,-13}{1,-13}{2,-13}{3,-13}{4,-13},str[0],str[1],str[2],str[3],str[4]);}}///summary///按ã¡ä学¡ì号?查¨¦询¡¥////summary///paramname=num/parampublicvoidFindStuNum(stringnum){foreach(stuinfostuinarryList){string[]str=(stu.showstuinfo()).Split(newchar[1]{''});if(str[0]==num){Console.WriteLine({0,-13}{1,-13}{2,-13}{3,-13}{4,-13},str[0],str[1],str[2],str[3],str[4]);}}}///summary///按ã¡ä姓?名?查¨¦询¡¥////summary///paramname=name/paramprivatevoidFindStuName(stringname){foreach(stuinfostuinarryList){string[]str=(stu.showstuinfo()).Split(newchar[1]{''});if(str[1]==name){Console.WriteLine({0,-13}{1,-13}{2,-13}{3,-13}{4,-13},str[0],str[1],str[2],str[3],str[4]);}}}#endregion#regio
本文标题:c#控制台学生管理系统
链接地址:https://www.777doc.com/doc-3391463 .html