Store list of ids and check it exist there or not
I have some id which i am getting from database matching some criteria specified there. No of id may be 100. I will store all that id at somewhere at loading of application. I have one continuos running process which return id and i want to check that returned id is exist in stored IDS. So how can i check it.I am t开发者_开发技巧hinking about some samrt way to do it.Otherwise i can check it with Loop. I don't want to check that using my sql query because it needs server connection at that time. In C# how can i check weather stored id is exist there or not and Which type of variable should i use to store all ids?
I'm not 100% sure what you're trying to do, but if you're trying to see which ids from a list still exist, you can do so via SQL. If your list of ids contains "2,3,5,7", you can check to see which of those still exists via:
select id from my_table where id in (2,3,5,7)
Or, if you're receiving an id from the user and you want to check whether it exists within a disconnected list of ids, use your ids as keys in a Dictionary<int, int>
. You can check whether an id exists with a simple call to ContainsKey
which will execute much faster than the loop you mentioned.
精彩评论