How to write a code as string variable (C#)

人盡茶涼 提交于 2019-12-11 15:49:23

问题


I'm working on exam in which when the student asked to something like (declare if statement) he will answer in Rich text box.

the question is: I want to search for the input of the student in that box, and therefore, I must declare a string that contains the code (as string) something like that:

string check = "            string stat = "new";
            if (stat == "new")
            {
                Console.WriteLine(stat);
            }
";

However, the problem is that, the escape characters and the other preserved voids such as (if).

Briefly: I want to create string that contains a code.

NOTE: I have tried the @ and putting \ before escape characters, but it didn't work.

Thanks


回答1:


This is called the escape sequence and looks like \ concatenated with " (or another symbol):

string check = " ... \" ...";

Where \" means "



来源:https://stackoverflow.com/questions/49394014/how-to-write-a-code-as-string-variable-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!