Object-oriented class 4-4 library delegates

Source: Internet
Author: User

First, class library

1, this is not a class library.

If within the company you don't have a code (not a very confidential code), your colleague will, and your colleague writes a code on his computer. Let you use on your own computer, how to do it? See below:

(1) Your colleague created a Qiuhe class.

namespace ConsoleApplication59   // Note namespace {    public  class  Qiuhe    {        publicint jiafa (intint  b)        {             return A + b;}}    }

(2) in the folder to find the name: Qiuhe.cs file, on your computer, you on your own computer, paste this file into the file you created, such as (first), and then your main function on the right side of the page "solution" has a "Show All Files" button, click, Just display the Qiuhe.cs file you need, select it, right-click, and select "Include In Project (J)" as (second). Add success!

(3) Refer to the Qiuhe.cs namespace in your action page, and then instantiate the Qiuhe, referencing the Jiafa method inside. Ok!!

2, the Real class library

If your company's main revenue is by selling code, then the code you sell to other companies will not let them see the specific code inside, it can not look like the above, this requires the class library.

(1) Create a class library with the name ClassLibrary5, and then click "Generate" ClassLibrary5 in "solution"

(2) Locate the file suffix. dll in debug, paste it into the debug file (ConsoleApplication61) of your operation, then click "References" on the right "solution" to find the DLL, file you pasted under the file.

(3) Reference namespace. Instantiate and refer to the method as above.

Second, the Commission

Note: The method you are delegating must be the same as the type of the method being delegated (necessary prerequisites)

1. Declaring the delegate type, (above the main function)

2. Create the delegate variable (f) and make the function point (new Qiuhe (). Jiafa) and perform the assignment operation.

At this point, f (AA,BB) is equivalent to Jia (A,BB).

Finish!!!

Object-oriented class 4-4 library delegates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.