• <legend id='Jbf6l'><style id='Jbf6l'><dir id='Jbf6l'><q id='Jbf6l'></q></dir></style></legend>

      <small id='Jbf6l'></small><noframes id='Jbf6l'>

      <i id='Jbf6l'><tr id='Jbf6l'><dt id='Jbf6l'><q id='Jbf6l'><span id='Jbf6l'><b id='Jbf6l'><form id='Jbf6l'><ins id='Jbf6l'></ins><ul id='Jbf6l'></ul><sub id='Jbf6l'></sub></form><legend id='Jbf6l'></legend><bdo id='Jbf6l'><pre id='Jbf6l'><center id='Jbf6l'></center></pre></bdo></b><th id='Jbf6l'></th></span></q></dt></tr></i><div id='Jbf6l'><tfoot id='Jbf6l'></tfoot><dl id='Jbf6l'><fieldset id='Jbf6l'></fieldset></dl></div>
    1. <tfoot id='Jbf6l'></tfoot>

        <bdo id='Jbf6l'></bdo><ul id='Jbf6l'></ul>

        如何合并2个List&lt;T&gt;并在 C# 中从中删除重

        时间:2023-08-27

        <small id='AGfwa'></small><noframes id='AGfwa'>

              <tbody id='AGfwa'></tbody>
            • <bdo id='AGfwa'></bdo><ul id='AGfwa'></ul>
                <tfoot id='AGfwa'></tfoot>
              1. <i id='AGfwa'><tr id='AGfwa'><dt id='AGfwa'><q id='AGfwa'><span id='AGfwa'><b id='AGfwa'><form id='AGfwa'><ins id='AGfwa'></ins><ul id='AGfwa'></ul><sub id='AGfwa'></sub></form><legend id='AGfwa'></legend><bdo id='AGfwa'><pre id='AGfwa'><center id='AGfwa'></center></pre></bdo></b><th id='AGfwa'></th></span></q></dt></tr></i><div id='AGfwa'><tfoot id='AGfwa'></tfoot><dl id='AGfwa'><fieldset id='AGfwa'></fieldset></dl></div>
              2. <legend id='AGfwa'><style id='AGfwa'><dir id='AGfwa'><q id='AGfwa'></q></dir></style></legend>

                  本文介绍了如何合并2个List&lt;T&gt;并在 C# 中从中删除重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有两个列表列表,我需要将它们合并到第三个列表中并从列表中删除重复值

                  I have two lists List that I need to combine in third list and remove duplicate values from that lists

                  有点难以解释,所以让我举一个例子来说明代码的样子和我想要的结果,在示例中我使用 int 类型而不是 ResultAnalysisFileSql 类.

                  A bit hard to explain, so let me show an example of what the code looks like and what I want as a result, in sample I use int type not ResultAnalysisFileSql class.

                  first_list = [1, 12, 12, 5]

                  first_list = [1, 12, 12, 5]

                  second_list = [12, 5, 7, 9, 1]

                  second_list = [12, 5, 7, 9, 1]

                  合并两个列表的结果应该是这个列表:结果列表 = [1, 12, 5, 7, 9]

                  The result of combining the two lists should result in this list: resulting_list = [1, 12, 5, 7, 9]

                  您会注意到结果有第一个列表,包括它的两个12"值,而在 second_list 中还有一个额外的 12、1 和 5 值.

                  You'll notice that the result has the first list, including its two "12" values, and in second_list has an additional 12, 1 and 5 value.

                  ResultAnalysisFileSql 类

                  ResultAnalysisFileSql class

                  [Serializable]
                      public partial class ResultAnalysisFileSql
                      {
                          public string FileSql { get; set; }
                  
                          public string PathFileSql { get; set; }
                  
                          public List<ErrorAnalysisSql> Errors { get; set; }
                  
                          public List<WarningAnalysisSql> Warnings{ get; set; }
                  
                          public ResultAnalysisFileSql()
                          {
                  
                          }
                  
                          public ResultAnalysisFileSql(string fileSql)
                          {
                              if (string.IsNullOrEmpty(fileSql)
                                  || fileSql.Trim().Length == 0)
                              {
                                  throw new ArgumentNullException("fileSql", "fileSql is null");
                              }
                  
                              if (!fileSql.EndsWith(Utility.ExtensionFicherosErrorYWarning))
                              {
                                  throw new ArgumentOutOfRangeException("fileSql", "Ruta de fichero Sql no tiene extensión " + Utility.ExtensionFicherosErrorYWarning);
                              }
                  
                              PathFileSql = fileSql;
                              FileSql = ObtenerNombreFicheroSql(fileSql);
                              Errors = new List<ErrorAnalysisSql>();
                              Warnings= new List<WarningAnalysisSql>();
                          }
                  
                          private string ObtenerNombreFicheroSql(string fileSql)
                          {
                              var f = Path.GetFileName(fileSql);
                              return f.Substring(0, f.IndexOf(Utility.ExtensionFicherosErrorYWarning));
                          }
                  
                  
                          public override bool Equals(object obj)
                          {
                              if (obj == null)
                                  return false;
                              if (!(obj is ResultAnalysisFileSql))
                                  return false;
                  
                              var t = obj as ResultAnalysisFileSql;
                              return t.FileSql== this.FileSql
                                  && t.PathFileSql == this.PathFileSql
                                  && t.Errors.Count == this.Errors.Count
                                  && t.Warnings.Count == this.Warnings.Count;
                          }
                  
                  
                      }
                  

                  任何用于合并和删除重复项的示例代码?

                  Any sample code for combine and removing duplicates ?

                  推荐答案

                  你看过 Enumerable.Union

                  此方法从返回集中排除重复项.这是不同的对 Concat 的行为方法,返回所有元素在输入序列中,包括重复.

                  This method excludes duplicates from the return set. This is different behavior to the Concat method, which returns all the elements in the input sequences including duplicates.

                  List<int> list1 = new List<int> { 1, 12, 12, 5};
                  List<int> list2 = new List<int> { 12, 5, 7, 9, 1 };
                  List<int> ulist = list1.Union(list2).ToList();
                  
                  // ulist output : 1, 12, 5, 7, 9
                  

                  这篇关于如何合并2个List&lt;T&gt;并在 C# 中从中删除重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从列表中删除重复项&lt;T&gt;在 C# 中 下一篇:如何从 List&lt;string&gt; 中查找所有重复项

                  相关文章

                  最新文章

                • <small id='BnioZ'></small><noframes id='BnioZ'>

                • <i id='BnioZ'><tr id='BnioZ'><dt id='BnioZ'><q id='BnioZ'><span id='BnioZ'><b id='BnioZ'><form id='BnioZ'><ins id='BnioZ'></ins><ul id='BnioZ'></ul><sub id='BnioZ'></sub></form><legend id='BnioZ'></legend><bdo id='BnioZ'><pre id='BnioZ'><center id='BnioZ'></center></pre></bdo></b><th id='BnioZ'></th></span></q></dt></tr></i><div id='BnioZ'><tfoot id='BnioZ'></tfoot><dl id='BnioZ'><fieldset id='BnioZ'></fieldset></dl></div>

                  <legend id='BnioZ'><style id='BnioZ'><dir id='BnioZ'><q id='BnioZ'></q></dir></style></legend>
                    <bdo id='BnioZ'></bdo><ul id='BnioZ'></ul>

                  <tfoot id='BnioZ'></tfoot>