当前位置:网站首页>C#的partial用法
C#的partial用法
2022-07-23 05:37:00 【王者之路001】
最近,在用C#做程序。
在做东西之前,发现原来的C#代码;看完之后,感觉头大;因为,代码实在太长了,一个功能类写几千行,而且,全都是这么写下来。
笔者牢记一个原则:好的代码,不是给机器用的,而是给人用的。看到这个现象,不觉头大。
就想起一个原则:对几千行代码进行拆分;正好,C#提供了一个partial关键字,可以对class、interface进行分割。
如下所示:
源文件A1.cs
public partial class A
{
public void test1();
}源文件A2.cs
public partial A
{
public void test2();
}等同于一个源文件A.cs
public class A
{
public void test1();
public void test2();
}挺理解部分工程师把一大堆功能写到一个类里面的;因为C#始终是一种面向对象的语言,相同类似的功能,最好的方式是写进一个具有相同的类里。但一大堆代码,显然不符合代码的简洁性和稳健型的原则。
但比较悲催的,不是所有的语言都有这个特性,如JAVA语言就没有这个特性;解决方法就是进行代码的精炼化。
当然了,目前,推动大家一起对代码进行重构和优化吧。
边栏推荐
- Cadence learning path (VIII) PCB placement components
- 部署storageclass踩坑记录
- The 12th Blue Bridge Cup embedded design and development project
- Redis source code and design analysis -- 5. Integer set
- Switch exchanges
- 6. Barycentric coordinate interpolation and graphics rendering pipeline
- Script of Nacos current limiting query
- Optimization Net application CPU and memory 11 practices
- "The six programming languages I want most!"
- Niuke brush questions - Sword finger offer (phase II)
猜你喜欢

Understand asp Net core - Cookie based authentication

Optimization Net application CPU and memory 11 practices

Anaconda虚拟环境下安装opencv报错的问题

UNITY VFX syntax error: unexpected token ‘#‘ at kernel CSMain

Alibaba cloud object storage service OSS front and rear joint debugging

3DMAX first skin brush weights, then attach merge

C语言n番战--链表(九)

Dynamic memory management

3dMax先蒙皮刷权重,再附加合并

Basic concepts of software testing
随机推荐
Xssgame games (XSS learning) level1-15
【视觉SLAM】ORB-SLAM: Tracking and Mapping Recognizable Features
赫克Hurco工控机维修WinMax数控机床控制器维修
Pytorch (V) -- pytorch advanced training skills
Redis源码与设计剖析 -- 9.字符串对象
sort
Mysql database foundation
Redis source code and design analysis -- 10. List object
Redis源码与设计剖析 -- 12.集合对象
Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?
Redis源码与设计剖析 -- 11.哈希对象
部署storageclass踩坑记录
Detailed explanation of structure
Notes and Thoughts on the red dust of the sky (III) as long as the conditions are sufficient, the results will come naturally
Kubernetes technology and Architecture (VI)
Redis source code and design analysis -- 7. Quick list
Dynamic memory management
R language uses DALEX package to explain and analyze the machine learning model built by H2O package: summary and Practice
UNITY VFX syntax error: unexpected token ‘#‘ at kernel CSMain
IO should know and should know