C# Partial:分部方法和分部类代码实例
作者:junjie 时间:2022-04-07 11:28:26
using System;
namespace Partial
{
class Program
{
static void Main(string[] args)
{
A a = new A();
}
}
partial class A
{
public A()
{
PrintHello();
PrintWorld();
Console.Read();
}
partial void PrintHello()
{
Console.Write("Hello");
}
}
partial class A
{
//分部方法必须存在如下声明,返回类型只可以为void,且不接受Out参数
//分部方法可以只存在声明而不实现它
//未实现的分部方法在代码生成时会自动被编译器移除,不会带来额外的开销
partial void PrintHello();
partial void PrintWorld();
}
}
这段代码只会输出:Hello,并且不会造成编译错误。
标签:C#,Partial,分部方法,分部类
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JWT在OpenFeign调用中进行令牌中继详解
2023-02-07 04:19:15
Java基础之final关键字作用案例
2022-11-02 19:23:35
![](https://img.aspxhome.com/file/2023/6/62126_0s.png)
java生成图片验证码示例程序
2023-09-13 10:17:57
MyBatis-Plus中更新操作的两种实现
2022-06-24 03:09:14
![](https://img.aspxhome.com/file/2023/7/65597_0s.jpg)
IDEA 2022 中的Lombok 使用基础教程
2023-04-09 21:57:09
![](https://img.aspxhome.com/file/2023/7/64547_0s.png)
java设计模式学习之工厂方法模式
2023-10-12 17:19:04
![](https://img.aspxhome.com/file/2023/7/58607_0s.jpg)
Android仿百度图片查看功能
2023-09-26 07:50:24
![](https://img.aspxhome.com/file/2023/8/85448_0s.jpg)
springboot如何实现自动装配源码解读
2023-11-10 15:44:20
浅谈Maven的安装及修改为阿里云下载依赖
2023-08-05 08:30:37
executor包执行器功能
2023-07-26 21:07:36
Java数据结构之AC自动机算法的实现
2023-08-31 07:23:57
![](https://img.aspxhome.com/file/2023/9/63779_0s.png)
用Java连接sqlserver数据库时候几个jar包的区别分析
2021-11-07 02:18:01
java基础之NIO介绍及使用
2022-06-07 11:30:14
![](https://img.aspxhome.com/file/2023/2/63672_0s.jpg)
java9开始——接口中可以定义private私有方法
2023-03-27 06:53:15
![](https://img.aspxhome.com/file/2023/1/66981_0s.png)
聊聊Redis的单线程模型
2022-02-21 09:20:42
![](https://img.aspxhome.com/file/2023/3/63293_0s.png)
JDK1.8安装与配置超详细教程
2023-09-20 16:17:50
![](https://img.aspxhome.com/file/2023/9/62809_0s.jpg)
springboot集成RestTemplate及常见的用法说明
2023-02-17 20:02:27
C++实现的O(n)复杂度内查找第K大数算法示例
2023-06-30 15:51:13
详解Java变量与常量
2023-11-09 21:00:14
![](https://img.aspxhome.com/file/2023/5/59005_0s.png)
Java C++ 算法题解leetcode652寻找重复子树
2022-08-17 23:58:09
![](https://img.aspxhome.com/file/2023/0/61120_0s.jpg)