永发信息网

c#如何自定义函数

答案:2  悬赏:0  手机版
解决时间 2021-03-02 11:09
  • 提问者网友:無理詩人
  • 2021-03-01 15:00
精选

最佳答案
  • 五星知识达人网友:野味小生
  • 2021-03-01 16:13
一、可以在ASP的源文件的<html>标记之前自定义函数
二、在Cs中先创建类,再创建函数,再调用

一、可以在ASP的源文件的<html>标记之前自定义函数,如:
<%@ Page Language="C#" CodeFile="randomName.aspx.cs" Inherits="randomName" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server" >


protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
Label1.Text = e.X.ToString();  //点击点的X坐标
Label2.Text = e.Y.ToString();   //点击点的Y坐标

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton_Click" ImageUrl="~/image1/head.jpg" /> //点击                                                        //时执行ImageButton_Click(object sender, ImageClickEventArgs e)函数
<asp:Label ID="Label1" runat="server" Text="Label" Width="74px"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label" Width="67px"></asp:Label></div>
</form>
</body>
</html>
二、在Cs中先创建类,再创建函数,再调用
public partial class _318 : System.Web.UI.Page
{
//  调用函数的方法,先创建一个类,如myclass,修饰符为public  static,调有时:类名.函数名,如myclass . returnst()
class myclass
{
public  static   string returnst(string  s)
{
return s;

}

}

protected void Page_Load(object sender, EventArgs e)
{
Response.Write( myclass . returnst("1223344555"));
}
}
全部回答
  • 1楼网友:鸽屿
  • 2021-03-01 17:03
类中方法全是函数 自已定义一个静态类,在类中定义静态函数,相当于全局函数,就象math.abs(int a)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯