Hello
I have such a code but it does not work. say db.count=0 and does not show its values.
var data_bot = bot_list.Intersect(da);
List db = new List();
db = data_bot.Select(sss => sss.ToString()).ToList();
List
db = data_bot.Select(sss => sss.ToString()).ToList();
VulpesPosted Oct 29, 2014, 11:13 AM
foreach(string s in da) Console.WriteLine(s);
then the output is again:
1
2
so I'd check first of all that you've copied the code correctly.
If you have, then some of the strings in 'da' can't be exactly of this pattern:
{source=ddd}
in particular there could be white-space at either side of the equals sign. If there is, then try re-ordering the Replace statements to remove white-space first:
da = da.Select(s => s.Replace(" ", "").Replace("{source=", "").Replace("}","")).ToList();
diamond diamondPosted Oct 29, 2014, 10:53 AM
VulpesPosted Oct 29, 2014, 10:38 AM
1
2
diamond diamondPosted Oct 29, 2014, 10:22 AM
VulpesPosted Oct 29, 2014, 9:58 AM
diamond diamondPosted Oct 29, 2014, 9:32 AM
VulpesPosted Oct 29, 2014, 9:21 AM
foreach(string s in db) Console.WriteLine(s);
VulpesPosted Oct 29, 2014, 9:05 AM
Try this instead:
which gives output of:
1
2
diamond diamondPosted Oct 29, 2014, 8:30 AM
VulpesPosted Oct 28, 2014, 7:35 PM
Of course, if 'bot_list' and 'da' have no elements in common, then their intersection will be empty and so too will the string list. So if you're unexpectedly getting an empty list, are you sure that its the intersection you wanted and not the union?
Incidentally, one thing you shouldn't do is this:
The problem with the first approach is that it creates a new List
This just uses up memory and the GC's time needlessly.
Ramesh MaruthiPosted Oct 28, 2014, 5:15 PM
What exactly do you get in data_bot ?
var data_bot = bot_list.Intersect(da);
db = data_bot.ConvertAll(sss =>Convert.ToString(sss));
otherway:
db =(data_bot.First() as Object[]).ToList().ConvertAll(sss =>Convert.ToString(sss));