How to add to List of Strings in one dictonary like dictonary in c#

First u can take 2 list of Strings

Var a =new List<string>(){"API","UI"} ;

var b=new List<string> (){"Application Programming Interface","User Interface"} ;


Result:
=====

API = Application Programming Interface
UI = User Interface



Firs you can create on extension method for this

      public static class ExtentionMethod
{
public static void YDR<T>(this IEnumerable dr,Action<T,int> y)
{
int initials = 0;
foreach (T item in dr)
{
y(item,initials ++);
}
}
}


         public static Dictionary<TKey,TValue> Adding<TKey, TValue>(IEnumerable<TKey> keys,IEnumerable<TValue> values)
{
var dictonary = new Dictionary<TKey,TValue>();

keys.YDR<TKey>((x,i) =>
{
dictonary .Add(x,values.ElementAt(i));
});

return dictonary;
}


Use case :
=======

Create a class and use this method


public Dictionary<string,string> GetValues(List<string> keys,List<string> values)
{
return Adding(keys,values);
}



===================================================================
This above is for Non duplicated values.
==================================================================
List<List<string,string>> lstData = new List<List<string,string>>();
for (int i = 0;i < a.Count;i++)
{
List<string,string> data = new List<string,string>();
data.Name = a[i];
data.Value =b[i];
lstData.Add(data);
}

Comments

Popular posts from this blog

Reverse Sentence using c#

How to write Pure java script Program?