资源描述:
《程序代码汇总第1章》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、原书P4-P5代码usingSystem;publicstructName{privatestringfname,mname,lname;publicName(stringfirst,stringmiddle,stringlast){fname=first;mname=middle;lname=last;}publicstringfirstName{get{returnfname;}set{fname=firstName;}}publicstringmiddleName{get{returnmname;
2、}set{mname=middleName;}}publicstringlastName{get{returnlname;}set{lname=lastName;}}publicoverridestringToString(){return(String.Format("{0}{1}{2}",fname,mname,lname));}publicstringInitials(){return(String.Format("{0}{1}{2}",fname.Substring(0,1),mname.Sub
3、string(0,1),lname.Substring(0,1)));}}publicclassNameTest{staticvoidMain(){NamemyName=newName("Michael","Mason","McMillan");stringfullName,inits;fullName=myName.ToString();inits=myName.Initials();Console.WriteLine("Mynameis{0}.",fullName);Console.WriteLin
4、e("Myinitialsare{0}.",inits);}}原书P5-P6代码usingSystem;publicclassIntStruct{staticvoidMain(){intnum;stringsnum;Console.Write("Enteranumber:");snum=Console.ReadLine();num=Int32.Parse(snum);Console.WriteLine(num);}}原书P12代码1publicvoidAdd(Objectitem){InnerList.
5、Add(item);}原书P12代码2publicvoidRemove(Objectitem){InnerList.Remove(item);}原书P13代码1publicnewintCount(){returnInnerList.Count;}原书P13代码2publicnewvoidClear(){InnerList.Clear();}原书P13-P14代码usingSystem;usingSystem.Collections;publicclassCollection:CollectionBase
6、{publicvoidAdd(Objectitem){InnerList.Add(item);}publicvoidRemove(Objectitem){InnerList.Remove(item);}publicnewvoidClear(){InnerList.Clear();}publicnewintCount(){returnInnerList.Count;}}classchapter1{staticvoidMain(){Collectionnames=newCollection();names.
7、Add("David");names.Add("Bernica");names.Add("Raymond");names.Add("Clayton");foreach(Objectnameinnames){Console.WriteLine(name);}Console.WriteLine("Numberofnames:"+names.Count());names.Remove("Raymond");Console.WriteLine("Numberofnames:"+names.Count());na
8、mes.Clear();Console.WriteLine("Numberofnames:"+names.Count());}}原书P15代码1staticvoidSwap(refTval1,refTval2){Ttemp;temp=val1;val1=val2;val2=temp;}原书P15代码2usingSystem;classchapter1{staticvoidMain(){intnum1=100;intnum2=200;C