C#程序经典实例

C#程序经典实例

ID:38978235

大小:17.49 KB

页数:6页

时间:2019-06-22

C#程序经典实例_第1页
C#程序经典实例_第2页
C#程序经典实例_第3页
C#程序经典实例_第4页
C#程序经典实例_第5页
资源描述:

《C#程序经典实例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、1、已知有Toys玩具表(1)利用SqlConnection,SqlCommand,SqlDataReader等输出整张表的数据publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}OleDbConnectionAconnStr;privatevoidForm1_Load(objectsender,EventArgse){}privatevoidbutton1_Click(objectsender,EventArgse){stringAfile="Provider=Microsoft.Jet.OLEDB.

2、4.0;DataSource=Toys.accdb";AconnStr=newOleDbConnection(Afile);MessageBox.Show("连接成功!");}privatevoidbutton2_Click(objectsender,EventArgse){AconnStr.Open();OleDbCommandAcmd=newOleDbCommand("selecttop5*fromToysorderbyToyId;",AconnStr);OleDbDataReaderodr=null;try{odr=Acmd.ExecuteReader();}catch(Ex

3、ceptionex){if(ex!=null)MessageBox.Show("执行出错!");}if(odr!=null){listBox1.Items.Add("ToyIdtToyNametToyRate");while(odr.Read()){stringTotalInfo="";TotalInfo+=odr["ToyId"].ToString()+"t";TotalInfo+=odr["ToyName"].ToString()+"";TotalInfo+=odr["ToyRate"].ToString()+"";listBox1.Items.Add(Total

4、Info+"");}odr.Close();}AconnStr.Close();}}(2)利用SqlConnection,SqlAdapter,DataSet,DataTable,dataGridView等输出价格在10元以下的玩具信息。2、编程实现:一列数的规则如下:1、1、2、3、5、8、13、21、34......求第30位数是多少,用递归算法实现。classProgram{publicstaticintF(inti){if(i<=0)return0;elseif(i>0&&i<=2)return1;elsereturnF(i-1)+F(i-2);}staticvoidM

5、ain(string[]args){Console.WriteLine(F(30));Console.ReadKey();}}3、编程实现对复数操作符的重载。publicclassComplex{publicintreal;publicintimaginary;publicComplex(intreal,intimaginary){this.real=real;this.imaginary=imaginary;}publicstaticComplexoperator+(Complexc1,Complexc2){returnnewComplex(c1.real+c2.real,c1.

6、imaginary+c2.imaginary);}publicstaticComplexoperator-(Complexc1,Complexc2){returnnewComplex(c1.real-c2.real,c1.imaginary-c2.imaginary);}publicstaticComplexoperator*(Complexc1,Complexc2){returnnewComplex(c1.real*c2.real-c1.imaginary*c2.imaginary,c1.real*c2.imaginary+c1.imaginary*c2.real);}publi

7、cstaticComplexoperator/(Complexc1,Complexc2){returnnewComplex(-c1.real*c2.real+c1.imaginary*c2.imaginary,-c1.real*c2.imaginary+c1.imaginary*c2.real);}publicoverridestringToString(){return(String.Format("{0}+{1}i",real,imaginary));}}clas

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。