如何在保持代码干燥的同时编写 quine?
quine 是一个打印自己的源代码而不从文件系统打开自身的程序。
下面是 C# 中此类 quine 的示例:
class Q{static void Main(){var s="class Q{{static void Main(){{var s={1}{0}{1};System.Console.Write(s,s,'{1}');}}}}";System.Console.Write(s,s,'"');}}
不过,这个解决方案对我来说似乎相当混乱且不优雅。这是一个很难维护的程序,因为每当您更改源代码时,您都必须在两个地方进行操作,即 编程的一大禁忌。
有没有一种用 C# 编写 quine 且不违反 DRY 原则的好方法?
A quine is a program that prints its own source code without opening itself from the filesystem.
Here is an example of such a quine in C#:
class Q{static void Main(){var s="class Q{{static void Main(){{var s={1}{0}{1};System.Console.Write(s,s,'{1}');}}}}";System.Console.Write(s,s,'"');}}
This solution seems pretty messy and inelegant to me, though. It's a terrible program to maintain because whenever you change the source, you have to do it in two places, which is a big programming no-no.
Is there a good way to write a quine in C# that doesn't violate the DRY principle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论