简体   繁体   English

C#检查剪贴板是否有效地包含重复项

[英]C# checking if a clipboard contains duplicates efficiently

I have a code that copies 30 strings to a clipboard at a time from a data source that gets updated randomly; 我有一个代码,一次从一个随机更新的数据源复制30个字符串到剪贴板; some times over a hundred new strings in under a second and some times there are no updates for a few minutes. 有时在一秒钟内有超过一百个新字符串,有时候几分钟内没有更新。 I want to send all the strings over sockets to a database. 我想通过套接字将所有字符串发送到数据库。 What would be the most efficient approach to sending the strings over sockets with out sending duplicates? 在发送重复项的情况下,通过套接字发送字符串的最有效方法是什么?

An easy but yet efficient way would be to check for and remove duplicates using LINQ right before you send your strings to the DB: 一种简单但有效的方法是在将字符串发送到DB之前使用LINQ检查并删除重复项:

string[] original; //the array where all the string from your clipboard are in

string[] newStrings = original.Distinct().ToArray();

This way you eliminate all duplicate strings from original . 这样就可以消除original所有重复字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM