如何将代码编写为字符串变量(C#) [英] How to write a code as string variable (C#)

查看:74
本文介绍了如何将代码编写为字符串变量(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆