How to customize the class and how to use a custom class

xiaoxiao2021-03-06  16

1. First write class files, such as Hello.cs

Using system;

Namespace Myclass.SAYHELLO

{

Public Class Tsayhello

{

String name;

Public tsayhello ()

{

THIS.NAME = "world";

}

Public String Say ()

{

Return ("Hello," this.name ");

}

}

}

2, compile custom class for DLL file

Csc.exe / target: library /r:system.dll Hello.cs

3, COPY generated hello.dll to the bin directory of the website root directory, if it is a virtual directory, copy to the BIN directory of the virtual directory

4, reference to custom class in the program

Using system;

Using system.Web.ui.webcontrols;

Using myclass.SAYHELLO;

/ / Reference Customized Namespace

Namespace myclasses

{

Public Class Ourgame: System.Web.ui.page

{

// Declare that the controls that will appear in Web Form

Public label lblsayhello;

Private Void Page_Load (Object Sender, System.EventArgs E)

{

Tsayhello myhello = new tsayhello ();

// Newly create a custom class object

LBLSAYHELLO.TEXT = myhello.say ();

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-41713.html

New Post(0)