.net平台与c#开发 小抄_第1页
.net平台与c#开发 小抄_第2页
.net平台与c#开发 小抄_第3页
.net平台与c#开发 小抄_第4页
.net平台与c#开发 小抄_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、专业好文档1.文件读写(1)写streamwriter sw = new streamwriter(c:ahut.txt,true);sw.writeline(安徽工业大学计算机学院网络工程系); sw.close(); 2)读streamreader sr = new streamreader(c:ahut.txt); string s = sr.readtoend(); console.writeline(s); sr.close();2(1)考勤信息if (this.radiobuttonlist1.selectedvalue.tostring().trim() = 手动添加) /略 e

2、lsethis.listbox1.items.clear();this.label1.visible = true;this.textbox1.visible = true; this.textbox1.text = 10; his.button1.visible = true;2(2)string constr=”integrated security=true; database=studentdb;server=localhost”;sqlconnection myconnect = new sqlconnection(constr);sqlcommand mycommand = new

3、 sqlcommand();mycommand.commandtext = select stuid,stuname from studentinfo;mycommand.connection = myconnect;myconnect.open();sqldatareader myreader = mycommand.executereader();myreader = mycommand.executereader();while (myreader.read() this.listbox1.items.add(myreader0.tostring().trim() + - + myrea

4、der1.tostring().trim();myreader.close(); int num = convert.toint32(this.textbox1.text.trim();int seed = (int)datetime.now.ticks) % 32767;random ranxuan = new random(seed);arraylist random = new arraylist(); arraylist random2 = new arraylist(); random.clear();random2.clear();random.add(ranxuan.next(0

5、, this.listbox1.items.count);int aa = (int)random0;random2.add(this.listbox1.itemsaa.text.tostring().trim();int i = 1;p: while (i = num)int ii = ranxuan.next(0, this.listbox1.items.count);for (int j = 0; j random.count; j+)if (ii = convert.toint16(randomj) goto p; random.add(ii);random2.add(this.lis

6、tbox1.itemsii.text.tostring().trim();i+; this.listbox1.items.clear();i = 0; while (i num)this.listbox1.items.add(random2i.tostring().trim(); i+;2(3)sqlconnection con=new sqlconnection();sqlcommand com=new sqlcommand();foreach (listitem li in listbox1.items) if (li.selected ) int k = li.text.trim().i

7、ndexof(-, 0); string stuid = li.text.trim().substring(0, k); string stuname = li.text.trim().substring(k+1, li.text.trim().length - k-1); string selectsql = insert into absenceinfo (stuid,stuname, absencemode, absencedate) values( + + stuid + + , + + stuname + + , + + this.dropdownlist1.selecteditem

8、.text.trim() + + , + + this.textbox2.text.trim() + ); string strcomm=selectsql;con = new sqlconnection(”integrated security=true; database=studentdb; server=localhost”); com = new sqlcommand(strcomm, con); con.open(); com.executenonquery(); con.close();3(1)创建一个list类的泛型集合实例,把下列人名:“张三”、“李四”、“王二”、“丁一”添

9、加到list集合中;using system.io; list mylist=new list(); string item; item=张三; mylist.add(item); /李四类推 3(2)使用streamwriter类把上面list集合中的每项需要遍历取出集合中每项一行行写入到“d:aaa.txt”文件中。 streamwriter sw=new streamwriter(d:aaa.txt,true); foreach(string s in mylist) sw.writeline(0,s); sw.close(); 2 3(3)使用streamreader类从“d:aaa.

10、txt”文件中把名字一行行读出并输出到控制台。 streamreader sr = new streamreader(d:aaa.txt); string s = sr.readtoend(); sr.close(); 4.构造一棵树 关于风景treenode node1,node2,parentnode; node1=new treenode(国内景点); treeview1.nodes.add(node1); node2=new treenode(国外景点); treeview1.nodes.add(node2); parentnode=node1; node1=new treenode(

11、黄山); parentnode.nodes.add(node1); node1=new treenode(九寨沟); parentnode.nodes.add(node1); parentnode=node2; node2=new treenode(埃及金字塔); parentnode.nodes.add(node2); node2=new treenode(希腊庙); parentnode.nodes.add(node2); 5.按钮单机事件using system.data.sqlclient; sqlconnection con= new sqlconnect(); con.connec

12、tionstring=persist security info=false;user id=sa;pwd=sa;database=user;server=localhost; con.open(); sqlcommmand cmd=new sqlcommand(); cmd.connection=con; cmd.commandtext=select * from userinfo where userid= + textbox1.text.tosting().trim()+ ; sqldatareader dr =cmd.executereader(); dr.read(); string

13、 pwd; try pws=dr1.tostring(); catch messagebox.show(用户名错误); if(text.box2.text.tosring().trim()!=pwd) messagebox.show(密码错误) return; else messagebox.show(登陆成功); con.close(); 6.在本地sql server服务器中一个数据库ml public sqldataadapter da; public dataset ds; string constring=persist security info=false;user id=sa;

14、 pwd=sa;database=ml;server=localhost ; string sql = select * from mlinfo; sqlconnection conn = new sqlconnection(connstring); da = new sqldataadapter(sql, conn); ds = new dataset(); da.fill(ds, mlinfo); datagridview1.datasource = ds.tables0; sqlcommandbuilder scb = new sqlcommandbuilder(da); 1.一系列数的

15、规则如下递归算法 class mainclasspublic static void show() console.writeline(foo(30); public static int foo(int i) if(i0&i=2) return 1; else return foo(i-1)+foo(i-2); 2. (1)学生类class studentstring sno;string sna;student(string sn,string sna)sno=sn; sname=sna;public void show()console.writeline(“学号=”+sno+”姓名=”

16、+sname); (2)添加并遍历public static void hand()arraylist arr1=new arraylist();student slisi=new student(“089074123”,”李四”);student swangwu=new student(“089074345”,”王五”);arr1.add(slisi); arr1.add(swangwu); student tempstudent; foreach(student s in arr1) tempstudent=(student)s; tempstudent.show(); 3. 数据库访问s

17、qlconnection con=new sqlconnection();con.connectionstring=”persist security info=false; user id=sa;pwd=sa;datebase=student;server=localhost ”;con.open;sqlcommand com=new sqlcommand(“select *from stuinfo”);sqldataadapter da=new sqldataadapter();da.selectcommand=com;dataset ds=new dataset();da.fill(ds

18、,”stuinfo”); for(int i=0;ids.tables0.rows.count;i+)for(int j=0;jds.tables0.coluns;i+) console.writeline(ds.tables0.rowsi.itemarrayj);console.writeline(); 10.答:父窗体给子窗体传值 可以调用重载子窗体的构造函数 直接传入相关数值 并调用子窗体form2的公开属性或方法 将form1的textbox1的值设置给form2的textbox2 在form2_load调用父窗体form1的公开属性或方法 将form1的textbox1的值设置给fo

19、rm2的textbox2 代码:form form2=new form(); form2.owner=this; form2.show(); this.hide(); 1、c#语言的特点 答:语法简洁、彻底的面向对象设计、与web紧密结合、强大的安全机制、完善的错误异常处理机制、灵活的版本处理技术、兼容性2、datareader和dataadapter的区别datareader:是对数据一次性前向只读的数据阅读器;基于连接,只读访问 适合较小数据量,返回的是一个数据读写器,只能一条条的读,操作起来不灵活,一般在只读的时候才用到;执行前必须先打开数据库,完成后也必须手动关闭。dataadapte

20、r:基于非连接,适于数据量较大时,可以另行修改,最后再把修改结果返回给数据库;要求资源也大一点,用fill方法将读取的数据放入数据集dataset ,dataset 的数据存在本地客户机内存;执行时自动打开数据库,完成后自动关闭连接。3、.net页面传递参数的方法及缺点答:session(viewstate): 简单,但易丢失 ;application:全局;cookie:简单,但可能不支持,可能被伪造;input ttype=hidden :简单,可能被伪造;url参数 :简单,显示于地址栏,长度有限; 数据库 :稳定,安全,但性能相对弱4、string和stringbuilding的区别和

21、联系:答:string的长度是不可变的,stringbuilder的长度是可变的。如果你对字符串中的内容经常进行操作,特别是内容要修改时,那么使用stringbuilder,如果最后需要string,那么使用stringbuilder的tostring()方法5、解释字符串:答:persist security info属性的意思是表示是否保存安全信息,其实可以简单的理解为ado在数据库连接成功后是否保存密码信息,true表示保存,false表示不保存;user id、pwd数据库登录用户名和密码;database数据库名称;server服务器名称。6、sqlcommand对象有3种方法对数据

22、库进行增删改查,请指明这3种方法的名称,并且说明他们的区别。(1)executenonquery可以使用 executenonquery 执行编录操作例如查询数据库的结构或创建诸如表等的数据库对象或通过执行 update、insert 或 delete 语句更改数据库中的数据。适合于 update、insert 或 delete 语句。 (2)executereader针对 connection 执行 commandtext并返回 dbdatareader。 返回reader,然后你while(reader.read() reader就是你的每一行的数据集。 (3)executescalar执

23、行查询并返回查询所返回的结果集中第一行的第一列。所有其他的列和行将被忽略。 适合于返回单一值。7、试说明datareader和dataset的区别。答:datset 连接数据库时是非面向连接的。把表全部读到sql中的缓冲池并断开于数据库的连接。 datareader 连接数据库时是面向连接的。读表时只能向前读取读完数据后有用户决定是否断开连接。8、请说明什么是装箱,什么是拆箱,并用代码举例。 装箱:把值类型转换为引用类型可以隐式转换。int i=0; object ob=i; 拆箱:把引用类型转换为值类型需显式转换。object ob =new object(); int j=(int)ob;

24、 9、请先指出集合和泛型集合的区别,再以集合arraylist为例,写出他的创建、添加和移除代码。答:泛型集合是集合的一种。是一组相关数据的集合。它能够按照一定的规律吧相关的数据组织在一起能通过“索引”或“下标”快速地管理这些数据。 集合是一组类似的对象在c#中任意类型的都想都可以放入一个集合中并将其视为object类型。 arraylist数组序列 (1)创建public arraylist或 public arraylistint capacity初始容量arraylist arr1=new arraylist 100或空(2)添加public int add(object value);

25、 public void addrange(icollection c) arraylist arr1=new arraylist(); object item=new object(); item=”hello”; arr1.add(item); arr2.add(arr1); (3)删除public void remove(object obj); arr1.remove(3); 10、请给出在父窗体form1中点击后打开子窗体form2的步骤,并给出代码。再说明在两winger tuivasa-sheck, who scored two tries in the kiwis 20-18

26、semi-final win over england, has been passed fit after a lower-leg injury, while slater has been named at full-back but is still recovering from a knee injury aggravated against usa.both sides boast 100% records heading into the encounter but australia have not conceded a try since josh charnleys ef

27、fort in their first pool match against england on the opening day.aussie winger jarryd hayne is the competitions top try scorer with nine, closely followed by tuivasa-sheck with eight.but it is recently named rugby league international federation player of the year sonny bill williams who has attrac

28、ted the most interest in the tournament so far.the kiwi - with a tournament high 17 offloads - has the chance of becoming the first player to win the world cup in both rugby league and rugby union after triumphing with the all blacks in 2011.id give every award back in a heartbeat just to get across

29、 the line this weekend, said williams.the (lack of) air up there watch mcayman islands-based webb, the head of fifas anti-racism taskforce, is in london for the football associations 150th anniversary celebrations and will attend citys premier league match at chelsea on sunday.i am going to be at th

30、e match tomorrow and i have asked to meet yaya toure, he told bbc sport.for me its about how he felt and i would like to speak to him first to find out what his experience was.uefa hasopened disciplinary proceedings against cskafor the racist behaviour of their fans duringcitys 2-1 win.michel platin

31、i, president of european footballs governing body, has also ordered an immediate investigation into the referees actions.cska said they were surprised and disappointed by toures complaint. in a statement the russian side added: we found no racist insults from fans of cska. baumgartner the disappoint

32、ing news: mission aborted.the supersonic descent could happen as early as sunda.the weather plays an important role in this mission. starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. the balloon, with capsule a

33、ttached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. it will climb higher than the tip of mount everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and i

34、nto the stratosphere. as he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.the balloon will slowly drift to the edge of space at 120,000 feet ( then, i would assume, he will slowly step out onto something resembling an olympic diving platform.they blew it in 2008 when they got caught cold in the final and they will not make the same mistake against the kiwis in manchester.five years ago they cruised through to the final and so

温馨提示

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

评论

0/150

提交评论