如何将代码编写为字符串变量(C#) [英] How to write a code as string variable (C#)
问题描述
我正在参加考试,当学生问类似(声明是否声明)之类的东西时,他会在Rich文本框中回答。
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);
}
";
但是,问题是转义字符和其他保留的空格(例如(if))。
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.
谢谢
推荐答案
这称为转义序列,看起来像是\与(或另一个符号)连接在一起:
This is called the escape sequence and looks like \ concatenated with " (or another symbol):
string check = " ... \" ...";
其中\表示
这篇关于如何将代码编写为字符串变量(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!