lundi 21 décembre 2020

Creating string text with if-else in linq

I want to get the result of more than one if else query in a single string in linq, I can get the result I want thanks to the method I wrote earlier, but I want to include it in my linq query.

I keep data from 4 columns in a row. I can operate with one line of this, but I want to receive data from 4 lines next to each other

Linq code:

select new{
   Ists = kart.FirstOrDefault(x => x.Id == sk.id) != 8
      ? kart.FirstOrDefault(x => x.Id == sk.id).ist1
      : ""
};

Example input:

ist1=ISTANBUL, ist2=KONYA, ist3=ANKARA, ist4=IZMIR

Output i want:

Ists= ISTANBUL + KONYA + ANKARA + IZMIR

Aucun commentaire:

Enregistrer un commentaire