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();

VulpesRank #55 · 29.2K reputationPosted Oct 29, 2014, 7:13 AM EDT
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();
VulpesRank #55 · 29.2K reputationPosted Oct 28, 2014, 3:35 PM EDT
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 MaruthiRank #937 · 2.2K reputationPosted Oct 28, 2014, 1:15 PM EDT
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));
diamond diamond131 reputationPosted Oct 29, 2014, 4:30 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 29, 2014, 5:05 AM EDT
Try this instead:
which gives output of:
1
2
VulpesRank #55 · 29.2K reputationPosted Oct 29, 2014, 5:21 AM EDT
foreach(string s in db) Console.WriteLine(s);
diamond diamond131 reputationPosted Oct 29, 2014, 5:32 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 29, 2014, 5:58 AM EDT
diamond diamond131 reputationPosted Oct 29, 2014, 6:22 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 29, 2014, 6:38 AM EDT
1
2
diamond diamond131 reputationPosted Oct 29, 2014, 6:53 AM EDT