在接触新的东西时总会小心翼翼,反复斟酌考虑,到底在哪里建立博客呢?真的好纠结,一如既往的选择恐惧,在浪费了诸多时间之后,还是觉得得果断点好,小公鸡点到谁就是谁,就这么愉快的决定了这个博客的降生。
-------2014.8.15. 9:19
已经在学校待了半个月了,想想都学了什么呢?c#,我的理解是另一种不同于c的语言,好像比c要麻烦,打印读入,都要写那么长的语句,相对于去年刚刚接触c时,这次的学习相对来说容易一些。
看书学习,看到别人在码代码,我们却在看书,这种很容易走神又无聊的工作,总是让我动放弃的念头。但是自己选择的路,跪着都要走下去,有句话叫做:既然......便要风雨兼程嘛!
刚开始看书,大体看了一眼c#的简介,说实话,不懂!待到学习怎样编写c#的时候,总算是让我找到一丝安慰,变量,运算符,布尔逻辑,goto语句,循环,分支,类型转化,字符串处理,枚举,数组,结构体,函数,这些基础都可以跟c相比较学习。就是以前都是用c的,现在用这个总觉得代码太麻烦,原来的printf也换成了console.writeline,都怪我太懒。
等看完了这个,就有了新任务,学生信息管理系统,天哪,我都没有用c编写过这个程序,好吧,那就只能先用c编写完再改成c#了,听说要用到链表,看链表,看到了链表中要用结构体和指针,好,再去看结构体和指针,看着看着,忘了自己要干嘛了,时间也都没有了,好吧。我放弃了用链表。第二天老老实实的用最基本的语句写了一个一百多行的代码,虽然第一次执行有好多错误,但还是比较有成就感的,光是找bug就找了一下午,学渣表示很苦恼嘛!不过我亲爱的六哥学长的帮助下,我还是把代码改好了。总结过200多行。在此得提一下,犯的错误和教训:
1、定义全局变量
2、如果两次录入成绩的话,该怎么接着上一次的成绩继续录入,我选择了用for循环,定义i等于total,首次录入total为0,但是第二次录入就可以从total开始了。
3、添加学生信息时,需要把一部分信息在结构体数组中往后移,在这会出现从array[i]向array[i+1]替换时,会让最左边的数据覆盖右边所有的数据,应该是从array[i+1]开始进行替换,也就是说,在替换之前,要确保数据存放的位置必须是空的。因此,要像删除某个数据,就可以用覆盖的办法。
4、在查找学生信息时,要区分学号和数组的下标。
不知道为什么在修改成c#的时候,却不能正确的执行。实在不知道哪里错了,我就悄悄的放弃了那个代码,重新写了一个没有用结构体的、用文件读取写入的新的学生信息管理系统。
//Read a Text File//读取 using System; using System.IO; namespace readwriteapp { class Class1 { [STAThread] static void Main(string[] args) { String line; try { //Pass the file path and file name to the StreamReader constructor StreamReader sr = new StreamReader("C:\\Sample.txt"); //Read the first line of text line = sr.ReadLine(); //Continue to read until you reach end of file while (line != null) { //write the lie to console window Console.WriteLine(line); //Read the next line line = sr.ReadLine(); } //close the file sr.Close(); Console.ReadLine(); } catch(Exception e) { Console.WriteLine("Exception: " + e.Message); } finally { Console.WriteLine("Executing finally block."); } } } }
//Write a text file - Version-1//写入 using System; using System.IO; namespace readwriteapp { class Class1 { [STAThread] static void Main(string[] args) { try { //Pass the filepath and filename to the StreamWriter Constructor StreamWriter sw = new StreamWriter("C:\\Test.txt"); //Write a line of text sw.WriteLine("Hello World!!"); //Write a second line of text sw.WriteLine("From the StreamWriter class"); //Close the file sw.Close(); } catch(Exception e) { Console.WriteLine("Exception: " + e.Message); } finally { Console.WriteLine("Executing finally block."); } } } }
//Write a text file - Version 2//写入 using System; using System.IO; using System.Text; namespace readwriteapp { class Class1 { static void Main(string[] args) { Int64 x; try { //Open the File StreamWriter sw = new StreamWriter("C:\\Test1.txt", true, Encoding.ASCII); //Writeout the numbers 1 to 10 on the same line. for(x=0; x < 10; x++) { sw.Write(x); } //close the file sw.Close(); } catch(Exception e) { Console.WriteLine("Exception: " + e.Message); } finally { Console.WriteLine("Executing finally block."); } } } }另外,还接触了一个新的语法 string[] names = students[j].Split(' '),可以把一个字符串以某个字符分成许多部分存储在数组中。
在完成这个代码以后,在继续看书中暂时放弃了c#,看了看c语言,敲了几个代码,打算敲够了之后继续学习c#,后面还有好多都没有看的知识呢!看看周围的学霸们,有种分分钟被鄙视的赶脚,身为学渣,我可以慢,但不能停,代码虐我千百遍,我定要拿他当初恋!fighting!