如何在字符串中同时使用 $ 和 @?

Jae*_*Lee 2 .net c# graphql

                    var request = new GraphQLRequest
                {
                    Query = @"
mutation {
  login(email: "{email}", password: "{password}") {
    userId,
    accessToken
  }
}"
                };
Run Code Online (Sandbox Code Playgroud)

我正在使用 C# 使用 GraphQL 进行编码

我想在字符串中插入“{email}”和“{password}”,但上面的代码无法正常工作:(

我如何解决这个问题..?请帮我

Ste*_*fan 5

您可以组合@$,如下所示:$@"Hi {username}!"

var somevalue = "your value";
//note: SO's code formatting is a bit off here
var str = $@"Hi
    This is, {somevalue} 
    and more";
Run Code Online (Sandbox Code Playgroud)

看看这个小提琴

注意:顺序$@至关重要。