第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

程序中呼叫Class(類)

標(biāo)簽:
JavaScript

如何在程序中呼叫你写好的Class(类)。为了实现这些功能,下面做了一个小小的例子。第一步,我们得把呼叫的类写好。

首先写一个interface(接口),这个接口有一个方法Call():

5acf07340001405b00110016.jpgICallable using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ICallable
/// </summary>
namespace Insus.NET
{
    public interface ICallable
    {
        void Call();
    }
}

 

下面写一个Class(类),它就是主角,是准备程序可以呼叫的类别。类别实作了上面的接口。

5acf07340001405b00110016.jpgAuthor using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Author
/// </summary>
namespace Insus.NET
{
    public class Author : ICallable
    {
        string _name;

        public Author(string name)
        {
            this._name = name;
        }

        public void Call()
        {
            HttpContext.Current.Response.Write("Hello," + _name);
        }
    }
}

 

下面分别用三种方式来呼叫类别,第一种,最普通的方法:Author obj = new Author(); 。

MethodA.aspx:

5acf07340001405b00110016.jpgMethodA.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MethodA.aspx.cs" Inherits="MethodA" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

 

MethodA.aspx.cs:

5acf07340001405b00110016.jpgMethodA.aspx.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class MethodA : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Author objAuthor = new Author("Insus.NET.");
        objAuthor.Call();
    }
}

 

第二种方法:

MethodB.aspx:

5acf07340001405b00110016.jpgMethidB.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MethodB.aspx.cs" Inherits="MethodB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

 

MethodB.aspx.cs:

5acf07340001405b00110016.jpgMethodB.aspx.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class MethodB : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Type oType = typeof(Author);
        Author objAuthor = (Author)Activator.CreateInstance(oType, new object[] { "Insus.NET." });
        objAuthor.Call();
    }
}

 

第三种方法,使用的Reflection(反射):

MethodC.aspx:

5acf07340001405b00110016.jpgMethodC.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MethodC.aspx.cs" Inherits="MethodC" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

 

MethodC.aspx.cs:

5acf07340001405b00110016.jpgMethodC.aspx.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using Insus.NET;

public partial class MethodC : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string classFullName = "Insus.NET.Author";
        Assembly assembly = Assembly.Load("App_Code");
        Type objType = assembly.GetType(classFullName);
        ICallable obj = (ICallable)Activator.CreateInstance(objType, new object[] { "Insus.NET." });
        obj.Call();
    }
}

 

三种方法执行的结果:


 

 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消