C#复习提纲.docx

上传人:b****5 文档编号:4712228 上传时间:2022-12-07 格式:DOCX 页数:20 大小:91.95KB
下载 相关 举报
C#复习提纲.docx_第1页
第1页 / 共20页
C#复习提纲.docx_第2页
第2页 / 共20页
C#复习提纲.docx_第3页
第3页 / 共20页
C#复习提纲.docx_第4页
第4页 / 共20页
C#复习提纲.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

C#复习提纲.docx

《C#复习提纲.docx》由会员分享,可在线阅读,更多相关《C#复习提纲.docx(20页珍藏版)》请在冰豆网上搜索。

C#复习提纲.docx

C#复习提纲

 

1、从键盘读入一个字符串,赋给变量i

intx=Convert.ToInt32(Console.ReadLine());

2、//将字符串转换为整型数据

intx=Convert.ToInt32(i);

3、//foreachp34

foreach(intindexinlist.Keys)

Console.WriteLine(index+"\t"+list[index]);

4、数组p47

1)定义:

int[,]b=newint[3,5];

2)长度:

for(inti=0;i

3)二维数组中,没有的元素,不显示,可以空着

【b[0]=newstring[2]{"b11","b12"};】

【b[1]=newstring[3]{"b21","b22","b23"};】【b[2]=newstring[5]{"a","e","i","o","u"};】

4)数组调整长度:

【String[]myArr={"fox","lazy","dog"};

【Array.Resize(refmyArr,myArr.Length+2);

5)数组的排序函数:

【Array.Sort(books);//升序函数

【Array.Reverse(books);//降序函数

【books.Contains("C#");//包含函数

【Array.IndexOf(books,"C#"));//元素在数组中的位置

6)将数组中的元素转换为字符

staticstring[]GetStrings(int[]a)

{

string[]s=newstring[a.Length];

for(inti=0;i

s[i]=a[i].ToString();

returns;

}

7)数组函数:

int[]a={10,20,4,8};

【a.Average()

【a.Sum()

【a.Max()

【a.Min()

5、字符p42

【string.Join(",",colorNames);//将各个字符用“,”连接

【stringstr=string.Format(

6、泛型p54-55

publicstaticvoidSwap(refTitem1,refTitem2)

{

Ttemp=item1;

item1=item2;

item2=temp;

}

7、列表p57

【Listlist=newList();

8、时间p61

【DateTimenow=DateTime.Now;

【stringstr=string.Format("{0:

现在是yyyy年M月d日,H点m分,dddd}",now);

9、数学函数Mathp62

 

 

SuperCombine:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.IO;

usingSystem.Data.SqlClient;

namespaceWindowsFormsApplication1

{

publicpartialclassSuperCombine:

Form

{

publicSuperCombine()

{

InitializeComponent();

}

//目录的创建事件

privatevoidbtnCreateDir_Click(objectsender,EventArgse)

{

try

{

if(!

txtPath.Text.Equals(""))

{

stringstr=txtPath.Text.Trim();

Directory.CreateDirectory(str);

MessageBox.Show("成功创建目录");

}

else

{

MessageBox.Show("请重新输入要建的目录!

");

}

}catch(Exceptionex)

{

throw(ex);

}

}

//文件创建的事件

privatevoidbtnCreateFile_Click(objectsender,EventArgse)

{

try

{

if(!

txtPath.Text.Equals(""))

{

stringstr=txtPath.Text.Trim();

File.Create(str);

MessageBox.Show("成功创建文件!

");

}

else

{

MessageBox.Show("请重新输入要创建文件!

");

}

}

catch(Exceptionex)

{

throw(ex);

}

}

//打开并显示某个目录下的所有文件的事件

privatevoidbtnOpen_Click(objectsender,EventArgse)

{

if(folderBrowserDialog1.ShowDialog()==DialogResult.OK)

{

textBox1.Text=folderBrowserDialog1.SelectedPath;

stringpath=textBox1.Text.Trim();

if(!

Directory.Exists(path))

{

MessageBox.Show("文件夹不存在!

");

return;

}

string[]files=Directory.GetFiles(path);

for(inti=0;i

{

stringtmp=Path.GetFileName(files[i]);

listBox1.Items.Add(tmp);

}

}

}

//打开所选的文件里的内容

privatevoidlistBox1_MouseDoubleClick(objectsender,MouseEventArgse)

{

stringfile=listBox1.SelectedItem.ToString();

file=textBox1.Text.Trim()+"\\"+file;

stringext=Path.GetExtension(file);

if(ext.ToLower()==".txt")

{

richTextBox1.Text=File.ReadAllText(file);

}

else

{

MessageBox.Show("请选择txt文件");

}

}

//combox控件的操作

privatevoidbtnShow_Click(objectsender,EventArgse)

{

try

{

//数据库连接部分

stringcon="server=localhost;uid=sa;pwd=as;database=db_course";

SqlConnectionsqlcon=newSqlConnection(con);

//提取数据库中的内容放入适配器,再放入datatable中

stringSQL="selectsnofromstudent";

SqlDataAdapterda=newSqlDataAdapter(SQL,con);

DataTabledt=newDataTable();

//适配器里的数据填充入dt中

da.Fill(dt);

comboBox1.Items.Clear();

for(inti=0;i

{

stringstrTemp1=dt.Rows[i]["sno"].ToString();

comboBox1.Items.Add(strTemp1);

}

}

catch(Exceptioned)

{

throw(ed);

}

}

privatevoidfileOpration_Load(objectsender,EventArgse)

{

timer1_Tick(null,null);

//datagridview的显示操作,调用数据库

try

{

stringcon="server=localhost;uid=sa;pwd=as;database=db_course";

SqlConnectionsqlcon=newSqlConnection(con);

stringSQL="select*fromstudent";

SqlDataAdapterda=newSqlDataAdapter(SQL,con);

DataTabledt=newDataTable();

da.Fill(dt);

dataGridView1.DataSource=dt;

}

catch(Exceptioned)

{

throw(ed);

}

}

//文件内容的实时更新

privatevoidbtnUpdateFile_Click(objectsender,EventArgse)

{

stringfile=listBox1.SelectedItem.ToString();

file=textBox1.Text.Trim()+"\\"+file;

stringext=Path.GetExtension(file);

File.WriteAllText(file,richTextBox1.Text);

MessageBox.Show("文件更新成功!

");

//再次刷新文件内容

listBox1_MouseDoubleClick(null,null);

}

//在状态栏动态显示本地时间fileOpration_Load中调用

privatevoidtimer1_Tick(objectsender,EventArgse)

{

timer1.Enabled=true;

timer1.Interval=1000;

timeshow.Text=DateTime.Now.ToString();

}

//dataGridView点击触发事件

privatevoiddataGridView1_Click(objectsender,EventArgse)

{

txtNum.Text=dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

txtSNo.Text=dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

txtSName.Text=dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

txtSAge.Text=dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

}

privatevoidbtnAdd_Click(objectsender,EventArgse)

{

stringstrSql="";

strSql="insertintostudent(sno,sname,sage)values('";

strSql=strSql+txtSNo.Text.Trim()+"','";

strSql=strSql+txtSName.Text.Trim().ToString()+"','";

strSql=strSql+txtSAge.Text.Trim().ToString()+"')";

try

{

stringcon="server=localhost;uid=sa;pwd=as;database=db_course";

SqlConnectionsqlcon=newSqlConnection(con);

SqlCommandcmd=newSqlCommand(strSql,sqlcon);

if(sqlcon.State!

=ConnectionState.Open)

sqlcon.Open();

intcount=cmd.ExecuteNonQuery();//

sqlcon.Close();

if(count>0)

{

MessageBox.Show("操作成功!

?

","提示");

fileOpration_Load(null,null);

}

}

catch(Exceptionex)

{throw(ex);}

}

privatevoidbtnDelete_Click(objectsender,EventArgse)

{

stringstrSql="";

strSql="deletefromstudentwheresno='"+txtSNo.Text+"'andsname='"+txtSName.Text+"'";

try

{

stringcon="server=localhost;uid=sa;pwd=as;database=db_course";

SqlConnectionsqlcon=newSqlConnection(con);

SqlCommandcmd=newSqlCommand(strSql,sqlcon);

sqlcon.Open();

cmd.ExecuteNonQuery();

sqlcon.Close();

MessageBox.Show("删除成功!

","提示");

fileOpration_Load(null,null);

}

catch(Exceptionex)

{throw(ex);}

}

}

}

//stringstrSql="update(Sno,sname,sage)values("+txtSNo.Text+","+txtSName.Text+","+txtSAge+","+")";

 

文件的操作

privatevoidbutton2_Click(objectsender,EventArgse)

{

stringpath1="e:

\\temp";

string[]files=Directory.GetFiles(path1);

for(inti=0;i

{

stringdirName=Path.GetDirectoryName(files[i]);

stringextName=Path.GetExtension(files[i]);

stringfileNameNoExt=Path.GetFileNameWithoutExtension(files[i]);

fileNameNoExt=(Convert.ToInt32(fileNameNoExt)).ToString();//去掉数字前面的“0"

【fileNameNoExt=fileNameNoExt.PadLeft(3,'0');】

stringfileName=dirName+"\\"+fileNameNoExt+extName;

File.Move(files[i],fileName);//能够使文件显示

}//for

 

//流水线插入学号

stringcon="server=localhost;uid=sa;pwd=as;database=Renee";

SqlConnectionsqlcon=newSqlConnection(con);

//执行查询到最大的学号

stringstrSql1="selectmax(sno)fromtestSno";

SqlCommandcom1=newSqlCommand(strSql1,sqlcon);

sqlcon.Open();

//执行查询,并返回查询所返回的结果集中的第一行的第一列,忽略其他行和列

stringvalue=com1.ExecuteScalar().ToString();

sqlcon.Close();

//截取后四位

stringstrLF=value.Substring(4,4);

intnumLF=Convert.ToInt32(strLF);//转换为int

numLF++;

//拼接字符串

stringnewLF=Convert.ToString(numLF).PadLeft(4,'0');

//解决convert.ToInt32,填充0

stringLast=value.Substring(0,4)+newLF;

//插入数据库

stringstrSql2="insertintotestSno(sno)values('"+Last+"')";

sqlcon.Open();

SqlCommandcom2=newSqlCommand(strSql2,sqlcon);

com2.ExecuteNonQuery();

sqlcon.Close();

//over

MessageBox.Show(Last);

//实现学号位数的扩充,如从0-999到0-9999的扩充

stringcon="server=localhost;uid=sa;pwd=as;database=Renee";

SqlConnectionsqlcon=newSqlConnection(con);

//执行查询到最大的学号

stringstrSql1="select*fromtestSno";

SqlCommandcom1=newSqlCommand(strSql1,sqlcon);

sqlcon.Open();

stringvalue=com1.ExecuteScalar().ToString();

sqlcon.Close();

SqlDataAdaptersda=newSqlDataAdapter(strSql1,sqlcon);

DataTabledt=newDataTable();

sda.Fill(dt);

for(inti=0;i

{

intid=Convert.ToInt32(dt.Rows[i]["id"]);

stringstrRg=dt.Rows[i]["sno"].ToString().Substring(0,4);

stringstrLF=dt.Rows[i]["sno"].ToString().Substring(4,4);

stringtemp=strRg+"0"+strLF;

//插入数据库

stringstrSql2="updatetestSnosetsno='"+temp+"'whereid='"+id+"'";

sqlcon.Open();

SqlCommandcom2=newSqlCommand(strSql2,sqlcon);

com2.ExecuteNonQuery();

sqlcon.Close();

}

删除当前行

privatevoid删?

除yToolStripMenuItem_Click(objectsender,EventArgse)

{

try

{

introw=dataGridView1.CurrentRow.Index;

if(row<0)

return;

stringsno=dataGridView1["sno",row].Value.ToString();

DialogResultresult=MessageBox.Show("确ā_实害_删?

除y学§号?

为a"+sno.Trim()+"的?

记?

录?

吗e?

?

","询ˉ问ê信?

息¢",MessageBoxButtons.YesNo,MessageBoxIcon.Question);

if(result==DialogResult.No)

return;

stringsql="deletefromstudentwheresno='"+sno+"'";

DBTOOL.SqlCmdOperation(sql);

MessageBox.Show("删?

除y成é功|!

?

");

}

catch(Exceptionex)

{

MessageBox.Show(ex.Message);

}

}

删除选中行

privatevoidtoolStripMenuItem2_Click(objectsender,EventArgse)

{

//删?

除y选?

中D行D

try

{

if(dataGridView1.SelectedRows.Count<=0)

{

MessageBox.Show("您ú还1没?

有瓺选?

中D行D!

?

");

return;

}

DialogResultresult=MessageBox.Show("确ā_实害_删?

除y吗e?

?

","询ˉ问ê信?

息¢",Message

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

当前位置:首页 > 高中教育 > 理化生

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1