.net平台与c#开发 小抄

上传人:laozhun 文档编号:2384196 上传时间:2023-02-17 格式:DOC 页数:7 大小:179.50KB
返回 下载 相关 举报
.net平台与c#开发 小抄_第1页
第1页 / 共7页
.net平台与c#开发 小抄_第2页
第2页 / 共7页
.net平台与c#开发 小抄_第3页
第3页 / 共7页
.net平台与c#开发 小抄_第4页
第4页 / 共7页
.net平台与c#开发 小抄_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《.net平台与c#开发 小抄》由会员分享,可在线阅读,更多相关《.net平台与c#开发 小抄(7页珍藏版)》请在三一办公上搜索。

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() = 手动添加) /略 elseth

2、is.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 SqlC

3、ommand();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() + - + myreader1.

4、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, thi

5、s.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.ListBox1

6、.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().IndexO

7、f(-, 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.Text

8、.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类的泛型集合实例,把下列人名:“张三”、“李四”、“王二”、“丁一”添加到Lis

9、t集合中;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.txt”文

10、件中把名字一行行读出并输出到控制台。 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.ConnectionS

12、tring=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 pwd;

13、 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; pwd=

14、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+”姓名=”+sNam

16、e); (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. 数据库访问Sqlcon

17、nection 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,”stu

18、info”); 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(); 待添加的隐藏文字内容210.答:父窗体给子窗体传值 可以调用重载子窗体的构造函数 直接传入相关数值 并调用子窗体Form2的公开属性或方法 将Form1的textBox1的值设置给Form2的textBox2 在Form2_Load调用父窗体Form1的公开属性或方法 将Form1的textBox1的

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

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

21、ng的区别和联系:答: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)ExecuteS

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

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

25、alue); 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

26、20-18 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 Charnl

27、eys effort 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

28、attracted 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

29、across 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

30、 at the 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

31、Platini, 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 disa

32、ppointing 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 cap

33、sule attached, 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)

34、 and into 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 i

35、n 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 far history has repeated itself here - the last try they conceded was scored by Englands Josh Charnley in the opening game of

36、the tournament.That could be classed as a weakness, a team under-cooked - but I have been impressed by the Kangaroos focus in their games since then.They have been concentrating on the sort of stuff that wins you tough, even contests - strong defence, especially on their own goal-line, completing se

37、ts and a good kick-chase. Theyve been great at all the unglamorous stuff that often goes unnoticed in the stands but not by your team-mates.It is as though their entire tournament has been preparation for the final.In Johnathan Thurston, Cooper Cronk, Cameron Smith and either Billy Slater or Greg In

38、glis at full-back they have a spine that is unmatched in rugby league. They have played in so many high-pressure games - a priceless asset going into Saturday.The Kiwis are a lot less experienced but winning a dramatic match like their semi-final against England will do wonders for their confidence.They defeated Australia in the Four Nations final in 2010 and the last World Cup, and know they can rise to the big occasion.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号