Create a condition within a Linq

Asked

Viewed 338 times

0

I need to make a comparison to set the value within mine select new. I’ll try to explain it better.

      var tipo= from t in p
                   select new
                   {
                       t.Key,
                       t.Value,
                   };

        return Ok(tipo);

I wanted to buy if t.key == "blue" were it, it would have only that amount. If it was something else, I would have the reference value. I tried to create an if() inside the Int, but the n language allows it. Does anyone have any idea how I can buy?

The amount I want to buy is with an Enummeration.

  • What is "this value" and "reference value"?

  • The name on my enummeration

  • This is very generic, specify exactly what you need to pick up. Remember that I don’t know your code.

  • I want to get from my new select only if value that comes from my screen is equal to a value that is in my Enummeration

1 answer

2

Your question is a little confused, but I think that’s what you need.

var tipo = from t in p
           select new
           {
               t.Key == "Azul" ? "ValorSeAzul" : "OutroValor",
               t.Value,
           };    

return Ok(tipo);

Browser other questions tagged

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