A Quine (Self-Replicating Program) Written in C#

Below is an example of a "quine" -- a program that prints out a copy of itself -- written in the C# programming language.

The fact that C# allows @-type strings to contain line breaks makes for an elegant quine. The string in blue is the "data" which the program processes. The logic is simple: examine each character in the data string. If the character is ^ , print a quote, the string, and a quote; otherwise print the character.

The string in blue is the "data" which the program processes. The fact that C# allows @-type strings to contain line breaks makes for an elegant quine. The logic is simple: Examine each character in the data string. If the character is ^ , print a quote, the string, and a quote; otherwise print the character.

Note: each indent is two spaces and all intra-line spaces are single.
   (char)34 is "
   (char)94 is ^

Learn more about quines here and here.

// Self Replication in the Key of C#
using System;
class Cell{
static void Transcribe(string DNA){
foreach (char c in DNA){
if ((int)c==94) Console.Write((char)34 + DNA + (char)34);
else Console.Write(c);}
Console.Read();}
static void Main(){Transcribe(@"//Self Replication in the Key of C#
using System;
class Cell{
static void Transcribe(string DNA){
foreach (char c in DNA){
if ((int)c==94) Console.Write((char)34 + DNA + (char)34);
else Console.Write(c);}
Console.Read();}
static void Main(){Transcribe(@^);}}
");}}

Back to Jared's Puzzle Page