Print your own source code with C #

zhaozj2021-02-16  93

Discover your own boring procedures. Take it out.

To make a program to output the same source code as yourself. First, you will want to define a string, the content of this string is the code of the source, and then output it. The most critical problem is that there is this string in the output program code itself, how to solve this problem? Not much to say, look at the following code.

Using system;

Using system.io;

Class OutputMyseelf

{

Static void main ()

{

CHAR C = (char) 34; // uses character c to represent "double quotation mark"

String str = "using system; use system.io; class outputmyself {static void main () {char c = (char) 34; string str =; streamwriter srd; srd = file.createtext (elwin.cs); Srd.Writeline (Str.Substring (0,97) C STR C STR.SUBSTRING (97, 41) C Str.Substring (138, 8) C Str.Substring (146)); SRD.CLOSE );}} ";

Streamwriter SRD;

SRD = file.createtext ("elwin.cs");

Srd.writeline (Str.Substring (0,97) C STR C STR.SUBSTRING (97, 41) C Str.Substring (138, 8) C Str.SUBSTRING (146));

Srd.close ();

}

}

An eLWIN.CS file is generated, the code is the same as the source program, and if you don't believe it, you copy it out to compile it.

转载请注明原文地址:https://www.9cbs.com/read-11635.html

New Post(0)