3

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?

Peter Olson
  • 139,199
  • 49
  • 202
  • 242
  • 2
    Why on earth would you expect to be able to write a neat, elegant, quine in a conventional programming language? – bmargulies Dec 05 '11 at 03:19
  • 1
    @bmargulies Because you can write neat, elegant quines in other programming languages, such as Javascript. Is there a reason I should expect C# to be incapable of elegantly handling such a simple task? – Peter Olson Dec 05 '11 at 03:46
  • Even if it is possible, I bet it still wouldn't be any more elegant. But that's subjective. I actually think the one you posted (which is pretty much the one everyone eventually comes up with when going for the shortest code) is pretty elegant in its way. – Igby Largeman Dec 05 '11 at 04:51

0 Answers0