asp.net 基本语法
一、委托
(1) 委托时一种引用方法的类型,一旦为委托分配了方法,委托将与该方法具有完全相同的行为,委托方法的带哦用可以像
其他方法一样,具有参数和返回值,
如: public delegate int PerformCalculation(int x, int y);
(2) 委托 是一种安全的封装方法的类型,与C++ 的函数指针类似,但委托时面向对象的,类型安全,
构造委托对象时,通常提供委托将包装的方法或使用匿名方法,实例化委托后,委托将把对它进行的方法调用传给方法,
调用方法给委托的参数被传递给方法,来自方法的返回值有委托返回给调用方,称为“调用委托”,
二、何时使用委托而不使用接口
1.以下情况使用委托:
当使用事件设计模式的时候
当封装静态方法可取的时候,
当调用方步需要访问实现该方法的对象中的其他属性 、方法或者接口
当需要方便的组合的时候
当类可能需要改方法的多个实现的时候
2. 以下情况使用接口
当存在一组可能被调用的相关方法时
当类只需要方法的单个实现的时候
当使用接口的累想要将该接口强制转换其他接口或者类类型的时候
当正在实现的方法链接到类的类型或者表示的时候,如:比较方法
三、委托合并, Del a, b, c, d;
a = Hello; //输出hello
b = Goodbye; //输出goodbye
// The two delegates, a and b, are composed to form c:
c = a + b; //输出hello goodbye
// Remove a from the composed delegate, leaving d,
// which calls o
相关文档:
第一步:
将某个页面的方法 有 webmethod attribute;
[WebMethod]
//只能是 public static 的方法
public static DateTime GetCurrentTime()
{
return DateTime.UtcNow;
}
第二步:
页面有一个ScriptManager 设置它的enablepagemethod=true;
asp:ScriptManager ID="Scri ......
ASP.NET defines an application as the sum of all files, pages, handlers, modules, and executable code that can be invoked or run in the scope of a given virtual directory (and its subdirectories) on a Web application server. For example, an "order" application might be published in the "/order ......
What is ASP.NET
ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Frame ......
//在当前页中关闭
Response.Write("<Script>window.opener.opener= null;window.opener.location.replace(window.opener.location.href='ideabank.aspx');window.close();</Script>");
//父类页打开 子页
Response.Write("<script>window.open('upideabank.aspx?id="+id+"','','height=50 ......