如果我可以使用两个或更多源文件编写一个类? [英] If I can write a class using two or more source files?

查看:91
本文介绍了如果我可以使用两个或更多源文件编写一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我的代码有4000行。我想写几个源文件。

但我发现不能写同名的两个文件。例如:

Because my code has 4000 lines. I want to write in several source files.
but I found can not write two file in same name.For example:

Inversion.cs //the first file
partial class forward
{ ... }
Inversion.cs //the second file
partial class forward
{ ... }



我该怎么办?


How can I do?

推荐答案

文件名限制非常明显:Windows要求您不能拥有两个具有相同名称的文件以防止混淆,就像您不能在这里使用相同用户名的两个人一样,或者两个具有相同注册的汽车数字!



单向循环是为所有文件添加前缀:

The file name restriction is pretty obvious: Windows requires that you can't have two files with the same name to prevent confusion, in the same way that you can't have two people here with the same username, or two cars with the same registration number!

One way round is to prefix all the files:
1.Inversion.cs
2.Inversion.cs
...


一般来说你做的是正确的,但是文件名称必须不同。

你在这里看到的是什么: http:// msdn .microsoft.com / zh-CN / library / wa80x488.aspx



建议命名相关文件为例如



Inversion.cs

Inversion.part2.cs



然后卸载你的项目并编辑项目在记事本中包含元素依赖的文件,你会很好地看到它们叠加

Well generally you're doing the right thing, but the file names must differ.
What you did you see here: http://msdn.microsoft.com/en-us/library/wa80x488.aspx

And recommendation for naming your related files is for instance

Inversion.cs
Inversion.part2.cs

then unload your project and edit the project file in notepad to include element depend upon and you will see them stack nicely
<Compile Include="Inversion.cs" />
<Compile Include="Inversion.part2.cs">
  <DependentUpon>Inversion.cs</DependentUpon>
</Compile>


部分类的概念可以让你溢出将类分成多个文件,并允许它们一起编译。这将有助于你分散你的课程。



一般来说,如果你的课程太大,有些事情是不对的。尝试重构代码。
The concept of partial classes can allow you to spilt the class into multiple files and yet allow them to compile together. This will help you split up your class.

in general though, if your class is too big, something's not right. Try refactoring your code.


这篇关于如果我可以使用两个或更多源文件编写一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆