2017年.net平臺與c#開發(fā) 小抄_第1頁
2017年.net平臺與c#開發(fā) 小抄_第2頁
2017年.net平臺與c#開發(fā) 小抄_第3頁
2017年.net平臺與c#開發(fā) 小抄_第4頁
2017年.net平臺與c#開發(fā) 小抄_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、.專業(yè)好文檔1.文件讀寫(1)寫StreamWriter sw = new StreamWriter("c:ahut.txt",true);sw.WriteLine("安徽工業(yè)大學計算機學院網(wǎng)絡(luò)工程系"); sw.Close(); 2)讀StreamReader sr = new StreamReader("c:ahut.txt"); string s = sr.ReadToEnd(); Console.WriteLine(s); sr.Close();2(1)考勤信息if (this.RadioButtonList1.Selecte

2、dValue.ToString().Trim() = "手動添加") /略 elsethis.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

3、 SqlConnection(constr);SqlCommand mycommand = new SqlCommand();mycommand.CommandText = "select StuID,StuName from studentinfo"mycommand.Connection = myconnect;myconnect.Open();SqlDataReader myreader = mycommand.ExecuteReader();myreader = mycommand.ExecuteReader();while (myreader.Read() thi

4、s.ListBox1.Items.Add(myreader0.ToString().Trim() + "-" + myreader1.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 = n

5、ew ArrayList(); random.Clear();random2.Clear();random.Add(ranxuan.Next(0, 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;

6、 j+)if (ii = Convert.ToInt16(randomj) goto P; random.Add(ii);random2.Add(this.ListBox1.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 SqlComman

7、d();foreach (ListItem li in ListBox1.Items) if (li.Selected ) int k = li.Text.Trim().IndexOf('-', 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, A

8、bsenceMode, AbsenceDate) values(" + "'" + stuid + "'" + "," + "'" + stuname + "'" + "," + "'" + this.DropDownList1.SelectedItem.Text.Trim() + "'" + "," + "'" + this.Te

9、xtBox2.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)創(chuàng)建一個List類的泛型集合實例,把下列人名:“張三”、“李四”、“王二”、“丁一”添加到List集合中;usin

10、g System.IO; List<string> myList=new List<string>(); 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,&q

11、uot;,s); sw.Close(); 2 3(3)使用StreamReader類從“d:aaa.txt”文件中把名字一行行讀出并輸出到控制臺。 StreamReader sr = new StreamReader("D:aaa.txt"); string s = sr.ReadToEnd(); sr.Close(); 4.構(gòu)造一棵樹 關(guān)于風景TreeNode node1,node2,parentnode; node1=new TreeNode("國內(nèi)景點"); treeView1.Nodes.Add(node1); node2=new TreeNod

12、e("國外景點"); treeView1.Nodes.Add(node2); parentnode=node1; node1=new TreeNode("黃山"); parentnode.Nodes.Add(node1); node1=new TreeNode("九寨溝"); parentnode.Nodes.Add(node1); parentnode=node2; node2=new TreeNode("埃及金字塔"); parentnode.Nodes.Add(node2); node2=new TreeNo

13、de("希臘廟"); parentnode.Nodes.Add(node2); 5.按鈕單機事件using System.Data.SqlClient; SqlConnection con= new SqlConnect(); con.ConnectionString="Persist Security Info=False;User id=sa;pwd=sa;database=User;server=localhost" con.Open(); SqlCommmand cmd=new SqlCommand(); cmd.Connection=con;

14、cmd.CommandText="select * from userinfo where userid=' " + textBox1.Text.ToSting().Trim()+ " ' " SqlDataReader dr =cmd.ExecuteReader(); dr.Read(); string pwd; try pws=dr1.ToString(); catch MessageBox.Show("用戶名錯誤"); if(text.Box2.Text.ToSring().Trim()!=pwd) Messag

15、eBox.Show("密碼錯誤") return; else MessageBox.Show("登陸成功"); con.Close(); 6.在本地SQL Server服務(wù)器中一個數(shù)據(jù)庫ML public SqlDataAdapter da; public DataSet ds; String constring="Persist Security Info=False;User id=sa; pwd=sa;database=ML;server=localhost " string sql = "select * from

16、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.一系列數(shù)的規(guī)則如下遞歸算法 Class mainclasspublic static void show()

17、 Console.writeline(Foo(30); Public static int Foo(int i) if(i<=0) return 0; Else if(i>0&&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

18、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. 數(shù)據(jù)庫訪問Sqlcon

19、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

20、info”); For(int i=0;i<ds.Tables0.Rows.Count;i+)for(int j=0;j<ds.Tables0.Coluns;i+) Console.Writeline(ds.Tables0.Rowsi.ItemArrayj);Console.Writeline(); 10.答:父窗體給子窗體傳值 可以調(diào)用重載子窗體的構(gòu)造函數(shù) 直接傳入相關(guān)數(shù)值 并調(diào)用子窗體Form2的公開屬性或方法 將Form1的textBox1的值設(shè)置給Form2的textBox2 在Form2_Load調(diào)用父窗體Form1的公開屬性或方法 將Form1的textBox1的值設(shè)置

21、給Form2的textBox2 代碼:Form Form2=new Form(); Form2.Owner=this; Form2.Show(); this.Hide(); 1、c#語言的特點 答:語法簡潔、徹底的面向?qū)ο笤O(shè)計、與web緊密結(jié)合、強大的安全機制、完善的錯誤異常處理機制、靈活的版本處理技術(shù)、兼容性2、DataReader和DataAdapter的區(qū)別DataReader:是對數(shù)據(jù)一次性前向只讀的數(shù)據(jù)閱讀器;基于連接,只讀訪問 適合較小數(shù)據(jù)量,返回的是一個數(shù)據(jù)讀寫器,只能一條條的讀,操作起來不靈活,一般在只讀的時候才用到;執(zhí)行前必須先打開數(shù)據(jù)庫,完成后也必須手動關(guān)閉。DataAda

22、pter:基于非連接,適于數(shù)據(jù)量較大時,可以另行修改,最后再把修改結(jié)果返回給數(shù)據(jù)庫;要求資源也大一點,用Fill方法將讀取的數(shù)據(jù)放入數(shù)據(jù)集DataSet ,DataSet 的數(shù)據(jù)存在本地客戶機內(nèi)存;執(zhí)行時自動打開數(shù)據(jù)庫,完成后自動關(guān)閉連接。3、.net頁面?zhèn)鬟f參數(shù)的方法及缺點答:session(viewstate): 簡單,但易丟失 ;application:全局;cookie:簡單,但可能不支持,可能被偽造;input ttype="hidden" :簡單,可能被偽造;url參數(shù) :簡單,顯示于地址欄,長度有限; 數(shù)據(jù)庫 :穩(wěn)定,安全,但性能相對弱4、string和str

23、ingbuilding的區(qū)別和聯(lián)系:答:STRING的長度是不可變的,StringBuilder的長度是可變的。如果你對字符串中的內(nèi)容經(jīng)常進行操作,特別是內(nèi)容要修改時,那么使用StringBuilder,如果最后需要String,那么使用StringBuilder的toString()方法5、解釋字符串:答:Persist Security Info屬性的意思是表示是否保存安全信息,其實可以簡單的理解為"ADO在數(shù)據(jù)庫連接成功后是否保存密碼信息",True表示保存,F(xiàn)alse表示不保存;User id、pwd數(shù)據(jù)庫登錄用戶名和密碼;database數(shù)據(jù)庫名稱;server服

24、務(wù)器名稱。6、sqlcommand對象有3種方法對數(shù)據(jù)庫進行增刪改查,請指明這3種方法的名稱,并且說明他們的區(qū)別。(1)ExecuteNonQuery可以使用 ExecuteNonQuery 執(zhí)行編錄操作例如查詢數(shù)據(jù)庫的結(jié)構(gòu)或創(chuàng)建諸如表等的數(shù)據(jù)庫對象或通過執(zhí)行 UPDATE、INSERT 或 DELETE 語句更改數(shù)據(jù)庫中的數(shù)據(jù)。適合于 UPDATE、INSERT 或 DELETE 語句。 (2)ExecuteReader針對 Connection 執(zhí)行 CommandText并返回 DbDataReader。 返回Reader,然后你while(reader.read() reader就是你

25、的每一行的數(shù)據(jù)集。 (3)ExecuteScalar執(zhí)行查詢并返回查詢所返回的結(jié)果集中第一行的第一列。所有其他的列和行將被忽略。 適合于返回單一值。7、試說明DataReader和DataSet的區(qū)別。答:DatSet 連接數(shù)據(jù)庫時是非面向連接的。把表全部讀到Sql中的緩沖池并斷開于數(shù)據(jù)庫的連接。 Datareader 連接數(shù)據(jù)庫時是面向連接的。讀表時只能向前讀取讀完數(shù)據(jù)后有用戶決定是否斷開連接。8、請說明什么是裝箱,什么是拆箱,并用代碼舉例。 裝箱:把值類型轉(zhuǎn)換為引用類型可以隱式轉(zhuǎn)換。int i=0; object ob=I; 拆箱:把引用類型轉(zhuǎn)換為值類型需顯式轉(zhuǎn)換。object ob =n

26、ew object(); int j=(int)ob; 9、請先指出集合和泛型集合的區(qū)別,再以集合ArrayList為例,寫出他的創(chuàng)建、添加和移除代碼。答:泛型集合是集合的一種。是一組相關(guān)數(shù)據(jù)的集合。它能夠按照一定的規(guī)律吧相關(guān)的數(shù)據(jù)組織在一起能通過“索引”或“下標”快速地管理這些數(shù)據(jù)。 集合是一組類似的對象在C#中任意類型的都想都可以放入一個集合中并將其視為object類型。 ArrayList數(shù)組序列 (1)創(chuàng)建public ArrayList或 public ArrayListint capacity初始容量ArrayList arr1=new ArrayList 100或空(2)添加pu

27、blic int Add(object value); 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 tw

28、o tries in the Kiwis' 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 conced

29、ed a try since Josh Charnley's effort in their first pool match against England on the opening day.Aussie winger Jarryd Hayne is the competition's top try scorer with nine, closely followed by Tuivasa-Sheck with eight.But it is recently named Rugby League International Federation player of t

30、he year Sonny Bill Williams who has 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."I'd gi

31、ve every award back in a heartbeat just to get across the line this weekend," said Williams.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifa's anti-racism taskforce, is in London for the Football Association's 150th anniversary celebrations and will attend C

32、ity's Premier League match at Chelsea on Sunday."I am going to be at the match tomorrow and I have asked to meet Yaya Toure," he told BBC Sport."For me it's about how he felt and I would like to speak to him first to find out what his experience was."Uefa has opened

33、disciplinary proceedings against CSKA for the "racist behaviour of their fans" during City's 2-1 win.Michel Platini, president of European football's governing body, has also ordered an immediate investigation into the referee's actions.CSKA said they were "surpr

34、ised and disappointed" by Toure's complaint. In a statement the Russian side added: "We found no racist insults from fans of CSKA." Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this

35、 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 attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will

36、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 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 in 2008 when they got caught cold in the final and they will not make the same mistake against the Kiwis in Man

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論