HI WELCOME TO KANSIRIS

Add Multiple Fields items to List C#

Leave a Comment
To Add Single Item to List
List<string> list1 = new List<string>();
list1.Add(“1”);
list1.Add(“2”);
list1.Add(“3”);
..
..
To Add Multiple items to List
List<string[]> list2 = new List<string[]>();
var firstitem = “1,2,3,4,…”;
var seconditem = “one,two,three,four,………”;
for(int i=0; i < firstitem.split(‘,’).Count();i++)
{
list2.Add(new string[]{firstitem.split(‘,’)[i],seconditem.split(‘,’)[i]});
}
output:
By Expanding List at debugging it would look like
>list2 | Count = 4 (depends on items count) > [0] >
[0] : “1”
[1] : “one”

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.