LINQ to SQL Deep Learning Series bis c#3.0 for the Enhancement of LINQ II

Source: Internet
Author: User

Most of this article is organized from MSDN

3. Partial method

A partial method enables the performer of a part of a class to define a method (similar to an event). The performer of another part of the class can decide whether to implement the method. If the method is not implemented, the compiler removes the method signature and all calls to the method. Therefore, any code in a partial class can use partial methods at will, even if no implementation is provided. If a method is invoked that is not implemented, it will not cause a compile-time error or a run-time error.

Partial methods are particularly useful when customizing the generated code. These methods allow the method name and signature to be preserved, so the generated code can invoke the method, and the developer can decide whether to implement the method. Very similar to partial classes, partial methods enable code created by the code generator and code created by developers to work together without generating run-time overhead.

A partial method declaration consists of two parts: definition and implementation. They can be in different parts of the partial class or in the same section.

Namespace PM
{
Partial class A
{
partial void onsomethinghappened (string s);
}
This part can is in a separate file.
Partial class A
{
Comment out of and the program
would still compile.
partial void onsomethinghappened (String s)
{
Console.WriteLine ("Something happened: {0}", s);
}
}
}

Related Article

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.