读书人

|M| 怎么在小弟我的类中return 掉当前

发布时间: 2012-01-02 22:40:04 作者: rapoo

|M| 如何在我的类中return 掉当前的操作
PageLoad()
{
if(!mybase.load())return;
...
...
}

mybase
public bool static load()
{
return false;
}
上面是我程序这样写的
我想能不能这样
-------------------
PageLoad()
{
mybase.load()
...
...
}

mybase
public void static load()
{
bool i=false;
if(i==false)
{
//在这里实现上面的功能,也就是让mybase.load()下面的程序不再执行
}
}

[解决办法]
public void static load()
{
bool i=false;
if(i==false)
{
....
return;
}
.....
}

[解决办法]
return;
throw Exception都会跳出当前的函数
[解决办法]
System.Web.HttpContext.Current.Response.End();
[解决办法]
ui.page里引用了mybase
而mybase里要控制page的行为(return 掉他的所有上级操作)
不建议这么做
page的逻辑放在page里就好了
[解决办法]
参考http://community.csdn.net/Expert/topic/5550/5550231.xml?temp=.5615045


private void button1_Click(object sender, EventArgs e)
{
try
{
f1();
}
catch (Ex1 ex)
{
Console.WriteLine(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
private void f1()
{
throw new Ex1( "this is f1 abort ");
}

public class Ex1 : Exception
{
public Ex1(string str)
: base(str)
{ }
}

读书人网 >asp.net

热点推荐