ComputersAreCool
ComputersAreCool

Reputation: 117

C#: Read Code Within Program at Line

(I am aware this may seem somewhat useless) So let's say I have a Console application named ConsoleApp1.cs with the following code:

1| Console.WriteLine("The ability for programs to reflect is revolutionary")
2| //Code to print line 1 as "Console.WriteLine("The ability for programs to reflect is revolutionary")"

How can I print (Console.WriteLine) a specified line of code in ConsoleApp1.cs as text?

Upvotes: 0

Views: 127

Answers (1)

hyankov
hyankov

Reputation: 4130

Closest you can get to, I think is:

Expression<Action> expr = () => Console.WriteLine("The ability for programs to reflect is revolutionary");
Console.WriteLine(expr.ToString()); 

Upvotes: 1

Related Questions