Create a condition within a Linq

0

I need to make a comparison to set the value within my select new . I'll try to explain better.

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

        return Ok(tipo);

I wanted to buy if t.key == "blue" if it were, it would only set this value. If it were something else, it would set the value. I tried to create an if () inside linq, but the language does not allow it. Does anyone have any idea how I can buy?

The amount I want to buy is with an Enummeration.

    
asked by anonymous 25.02.2015 / 19:47

1 answer

2

Your question is a bit confusing, 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);
    
25.02.2015 / 19:55