C# 应该是蛮简单的一个问题

lisa9342 2012-08-31 09:10:01

//根据用户选择来确定要被发送的文件格式
ArrayList sendType = new ArrayList();
if (Utils.xml.ToString() == "true")
sendType.Add(".xml");
if (Utils.eml.ToString() == "true")
sendType.Add(".eml");
if (Utils.doc.ToString() == "true")
sendType.Add(".doc");
if (Utils.docx.ToString() == "true")
sendType.Add(".docx");
if (Utils.xls.ToString() == "true")
sendType.Add(".xls");
if (Utils.xlsx.ToString() == "true")
sendType.Add(".xlsx");
if (Utils.txt.ToString() == "true")
sendType.Add(".txt");
if (Utils.pdf.ToString() == "true")
sendType.Add(".pdf");
if (Utils.rar.ToString() == "true")
sendType.Add(".rar");
if (Utils.zip.ToString() == "true")
sendType.Add(".zip");

foreach (string f in files)
{
//先检查文件名
string path = f;
string newpath = path;
string fullname = Path.GetFileName(path);//返回文件名和后缀名
string name = Path.GetFileNameWithoutExtension(path);//返回文件名
string extn = Path.GetExtension(path);//返回后缀名
if (!sendType.Contains(extn))
break;
byte[] Bytes = System.Text.Encoding.Default.GetBytes(fullname);//获得文件名+后缀名的字节数组
byte[] nameBytes = System.Text.Encoding.Default.GetBytes(name);//获得文件名的字节数组
byte[] extnBytes = System.Text.Encoding.Default.GetBytes(extn);//获得后缀名的字节数组
string newname = fullname;//新(文件名+后缀名)
……


我用break调试的结果是,如果文件格式不对应的话就又从文件夹的第一个文件开始遍历,而我想不对应的时候就不往下进行其他操作,再从下一个文件检查,该用什么语句?
...全文
110 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙泉剑 2012-08-31
  • 打赏
  • 举报
回复
break是退出整个循环,continue是退出本次循环
shizhu820228 2012-08-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

将break改成continue
[/Quote]

对的。
lisa9342 2012-08-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
将break改成continue
[/Quote]

对头!
cry222222 2012-08-31
  • 打赏
  • 举报
回复
上面的回答都可以实现啊!
小志 2012-08-31
  • 打赏
  • 举报
回复
将break改成continue
天下如山 2012-08-31
  • 打赏
  • 举报
回复
难道不可以使用if(){} 当false的时候则不进行下一步操作 而又开始foreach的下一个开始 如此循环.
EnForGrass 2012-08-31
  • 打赏
  • 举报
回复
那你用switch处理吧

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧