How to quote a message

Asked

Viewed 81 times

0

if(string.IsNullOrEmpty(pessoa.Nome))
{
    ModelState.AddModelError("Nome", "O campo nome é obrigatório");
}

How do I quote inside the message?

Ex.: The "name" field is required.

  • 2

    ModelState.AddModelError("Nome", "O campo \"nome\" é obrigatório");

1 answer

1


You can do it two ways:

Using backslash ():

if(string.IsNullOrEmpty(pessoa.Nome))
{
    ModelState.AddModelError("Nome", "O campo \"nome\" é obrigatório");
}

Or using arroba (@) with duplicate double quotes:

if(string.IsNullOrEmpty(pessoa.Nome))
{
    ModelState.AddModelError("Nome", @"O campo ""nome"" é obrigatório");
}
  • The bar seems to me to have more logic, indicating that that character is part of the text. How does @work? Instead of using the slider I use quotes to indicate that it is a text?

  • Instead of using the escape bar, you use duplicate double quotes. The second has some interesting applications, if you want to use backslash, instead of putting two bars to escape, you can just insert a @ in the front, as the

Browser other questions tagged

You are not signed in. Login or sign up in order to post.