金属缠绕垫型号:asp.net(c#),请问如何定义一个公共的函数然后在各个页面调用?这样省去了一些工作量

来源:百度文库 编辑:高校问答 时间:2024/05/04 07:00:36
asp.net(c#),请问如何定义一个公共的函数然后在各个页面调用?这样省去了一些工作量

做一个公共的类:
public YourNameSpace{
class Function{
void static YourFunction1(...);
bool static YourFunction2(...);
}
}

调用的时候:
using YourNameSpace;

Function.YourFunction1(...);
bool bRet = Function.YourFunction2(...);

写一个类,把要重复应用的函数封装好就ok了,你可以把它编译成dll文件
例如:
using System;
using System.Text;
using System.Reflection;

/// <summary>
/// Summary description for Class1
/// </summary>
///
namespace cc
{
public class CUseData
{
private string _ConnectString;
public CUseData()
{
}
public string ConnectString
{
get
{
return _ConnectString;
}
set
{
_ConnectString = value;
}
}
public int ConnectStringLength()
{
return _ConnectString.Length;
}

}
}

在应用的文件中:
<%@ Import Namespace="cc" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
CUseData cu = new CUseData();
cu.ConnectString = "a";
int i = cu.ConnectStringLength();
Label1.Text = i.ToString();
}
</script>

通过 interface, class 或 struct 来作