You must Sign In to post a response.
  • Category: .NET

    Split the list value and separatly Text, Value by LINQ

    Hi Everyone,

    I have a list values like this,




    Now I want to split by : and Separate Text and Value by LINQ. I done this one by coding.

    public list<selectlistitem> converttoselectlistitem(list<string> data)
    list<selectlistitem> lst = new list<selectlistitem>();
    foreach (var item in data)
    var tempdatalist = new selectlistitem();
    tempdatalist.value = item.split(':')[0];
    tempdatalist.text = item.split(':')[1];
    return lst;

    Here I passed the list values to this method. But I want to do by LINQ. How to do.
  • #763084
    Hai Lawrence,
    Please see the below detailed answer:

    string[] listValues= {100000: "High", 200000: "Medium", 300000: "Low"}
    listValues = listValues.SelectMany(n => n.Split(':')).ToArray();
    foreach(var x in listValues)

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments