首页 新闻 会员 周边

C#编写的小程序

0
[已解决问题] 解决于 2016-12-14 14:10
这个程序的错误提示是

错误 1 未能找到类型或命名空间名称“SaveEmail”(是否缺少 using 指令或程序集引用?) G:\C#实验\第七章\实例7-5\实例7-5\Form1.cs 24 13 实例7-5

能不能看一下应该怎么改?



using
System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace 实例7_5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCheakEmail_Click(object sender, EventArgs e) { SaveEmail saveEmail = new SaveEmail(); try { if (saveEmail.CheckEmail(txtEmail.Text)) { lblShow.Text = "检查成功"; } } catch(EmailErrorException ex) { lblShow.Text = ex.Message; } } } public class EmailErrorException : ApplicationException { public EmailErrorException() { } public EmailErrorException(string message) : base(message) { } public EmailErrorException(string message, System.Exception innerException) : base(message, innerException) { } public override string Message { get { return "Email格式不正确:" + base.Message; } } public class SaveEmail { public bool CheackEmail(string email) { string[] strSign = email.Split('@'); if (strSign.Length != 2 || strSign[0].Length == 0 || strSign[1].Length == 0) { throw new EmailErrorException("@符号不正确!"); } else { int index = strSign[1].IndexOf('.'); if (index <= 0 || index >= strSign[1].Length - 1) { throw new EmailErrorException(".符号不正确"); } } return true; } } } }
C#
蓝烟的主页 蓝烟 | 菜鸟二级 | 园豆:206
提问于:2016-12-09 17:52
< >
分享
最佳答案
0

你把SaveEmail这个类拿出来,不要写在EmailErrorException里面

奖励园豆:5
龙葛格 | 小虾三级 |园豆:782 | 2016-12-12 11:34
其他回答(1)
0

把SaveEmail这个class提出来。

或者SaveEmail saveEmail = new SaveEmail();

改为EmailErrorException.SaveEmail saveEmail=new EmailErrorException.SaveEmail();

Daniel Cai | 园豆:10424 (专家六级) | 2016-12-09 18:00

我改了,但是CheckEmail下面又提示有错

支持(0) 反对(0) 蓝烟 | 园豆:206 (菜鸟二级) | 2016-12-09 18:18

我改了,但是CheckEmail下面又提示有错

支持(0) 反对(0) 蓝烟 | 园豆:206 (菜鸟二级) | 2016-12-09 18:18

@蓝烟: 看你的代码应该还是class路径不对,把你的鼠标移动到出错的代码上,应该会在出错的代码右下角出现一个小图标,点一下,它会提示你更改办法。你就选择正确的选项进行更改即可。

支持(0) 反对(0) Daniel Cai | 园豆:10424 (专家六级) | 2016-12-09 18:32

@Daniel Cai: 我用的是VS2010没有提示我该怎么改

支持(0) 反对(0) 蓝烟 | 园豆:206 (菜鸟二级) | 2016-12-09 20:45

@蓝烟:
我不知道你具体怎么改的。也不知道你具体是什么报错,所以没办法给出解决方案

支持(0) 反对(0) Daniel Cai | 园豆:10424 (专家六级) | 2016-12-09 20:46

@Daniel Cai: 嗯好吧,谢谢

支持(0) 反对(0) 蓝烟 | 园豆:206 (菜鸟二级) | 2016-12-09 21:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册