我是generating string dynamically
和passed to method for further execution
。
我希望;(semicoln)
之后的每个字符串都在新行上,因为;(semicolon)
是我无法解析的字符。
string myCode = "MyClient client = new MyClient();
var result = Task.Run(() =>
client.For<Customer>().FindEntriesAsync()).Result.AsEnumerable<Customer>();
return JsonConvert.SerializeObject(result);";
现在我管理上面的字符串如下,但是如果输入在字符串之上,如何在单个代码中进行操作?
string myCode = "MyClient client = new MyClient();";
myCode += Environment.NewLine + "var result = Task.Run(() =>
client.For<Customer>().FindEntriesAsync()).Result.AsEnumerable<Customer>();";
myCode += Environment.NewLine + "return JsonConvert.SerializeObject(result);";
答案 0 :(得分:6)
前缀@
允许内联换行:
string myCode = @"MyClient client = new MyClient();
var result = Task.Run(() => client.For<Customer>().FindEntriesAsync()).Result.AsEnumerable<Customer>();
return JsonConvert.SerializeObject(result);";
它甚至适用于Stackoverflow语法高亮,非常好。
答案 1 :(得分:4)
试试这个:
String.Join(Environment.NewLine, text.Split(';'));