Sunday 4 April 2021

C# How to Copy Tuple List Values into Integer Array

 void Main()
{
    List<Tuple<int,string>> ab = new List<Tuple<int,string>>();
    ab.Add(Tuple.Create(1,"hello1"));
    ab.Add(Tuple.Create(2,"hello2"));
    ab.Add(Tuple.Create(3,"hello3"));
    ab.Add(Tuple.Create(4,"hello4"));
    ab.Add(Tuple.Create(5,"hello5"));
    ab.Add(Tuple.Create(6,"hello6"));
    ab.Add(Tuple.Create(7,"hello7"));
    //ab.Dump();
    
    string g = "";
    
    int[] x = new int[ab.Count()];    
    int counter = 0;
    foreach(var r in ab)
    {
        if(r.Item1%2==0)
        {
            x[counter] = r.Item1;    
            counter++;
        }
    }
    x.Dump();
    
    var result = ab.Where(p=>x.Contains(p.Item1)).ToList();
    result.Dump();
}

// Define other methods and classes here


Output:-

No comments:

Post a Comment