C#又一段段代码求完整注释 谢谢.

2025-02-27 04:36:00
推荐回答(2个)
回答1:

//定义一个16位整数,并把ComboBox3 的选择索引赋给它
Int16 p=Convert.ToInt16(comboBox3.SelectedIndex);
if(p==-1) //如果没有选择
{
MessageBox.Show("请您选择文件夹操作方式","警告信息",
MessageBoxButtons.OK,MessageBoxIcon.Information);//给出警告消息框
}
else//如果选择了
{
//创建两个字符串,并把两个路径记录下来
string sourcepath=@"c:\1";
string targetpath=@"c:\2";
//下面这句应该是实例化一个类对象,要去这个类中看才知道是什么意思
MyFileOption myoption = new MyFileOption();
string[] filesname = null;//创建一个空字符串数组
/*把类的文件夹操作(源路径,目标路径,选择序号,输出参数 字符串数组)的操作结果赋给布尔变量i,同时到到文件名数组,在filesname 中*/
bool i=myoption.DirectoryOption(sourcepath,targetpath,p,out filesname);
if(i==true)//如果操作成功
{
MessageBox.Show("磁盘文件夹操作成功","保存信息",
MessageBoxButtons.OK, MessageBoxIcon.Information);//给出提示消息
if (filesname != null)//如果返回的文件名数组不为空
{
foreach (string somestring in filesname)//遍历所有文件名
{
richTextBox1.Text += somestring + "\r\n";//把文件名加到richTextBox 中,每个后面把光标移到行首,换行
}
}
}
else//为空给出操作出错的提示
{
MessageBox.Show("磁盘文件夹操作时出错", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}

回答2:

///


/// 文件夹操作
///

///
///
private void button6_Click(object sender, EventArgs e)
{
Int16 p=Convert.ToInt16(comboBox3.SelectedIndex);//获取复选框下标
if(p==-1)
{
MessageBox.Show("请您选择文件夹操作方式","警告信息",
MessageBoxButtons.OK,MessageBoxIcon.Information); //当没选择的时候弹框警告
}
else
{
string sourcepath=@"c:\1"; //路径
string targetpath=@"c:\2";//目标文件路径
MyFileOption myoption = new MyFileOption();//这应该是你自己写的io 类吧
string[] filesname = null;//声明文件名 的数组
bool i=myoption.DirectoryOption(sourcepath,targetpath,p,out filesname);//调用 类里面的方法
if(i==true)
{
MessageBox.Show("磁盘文件夹操作成功","保存信息",
MessageBoxButtons.OK, MessageBoxIcon.Information);
if (filesname != null)
{
foreach (string somestring in filesname)//遍历数组
{
richTextBox1.Text += somestring + "\r\n";
}
}
}
else
{
MessageBox.Show("磁盘文件夹操作时出错", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}