【问题标题】:Compare list<object1> and list<object2>比较 list<object1> 和 list<object2>
【发布时间】:2018-01-06 20:33:09
【问题描述】:

colDiffUpdated 和 colDiffTarget 有不同的值,如何将两个列表的差异添加到 colTypes?

假设每个列表都有不同的值。

   public List<columnTypes> colType = new List<columnTypes>();
            public List<coldiffTypes> colDiffUpdated = new List<coldiffTypes>();
            public List<coldiffTypesTarget> colDiffTarget = new List<coldiffTypesTarget>();

这是我存储值的类

public class columnTypes
    {
        public string tblName { get; set; }
        public string colName { get; set; }
        public int maxLength { get; set; }
        public string maxLengthStr { get; set; }
        public bool isUnique { get; set; }
        public bool isKey { get; set; }
        public System.Type dataType { get; set; }
        public bool isNullable { get; set; }
        public bool isAutoIncrement { get; set; }
        public string dataTypeName { get; set; }
        public int numericPrecision { get; set; }
        public int numericScale { get; set; }
    }

    public class coldiffTypes
    {
        public string tblName { get; set; }
        public string colName { get; set; }
        public int maxLength { get; set; }
        public string maxLengthStr { get; set; }
        public bool isUnique { get; set; }
        public bool isKey { get; set; }
        public System.Type dataType { get; set; }
        public bool isNullable { get; set; }
        public bool isAutoIncrement { get; set; }
        public string dataTypeName { get; set; }
        public int numericPrecision { get; set; }
        public int numericScale { get; set; }
    }

    public class coldiffTypesTarget
    {
        public string tblName { get; set; }
        public string colName { get; set; }
        public int maxLength { get; set; }
        public string maxLengthStr { get; set; }
        public bool isUnique { get; set; }
        public bool isKey { get; set; }
        public System.Type dataType { get; set; }
        public bool isNullable { get; set; }
        public bool isAutoIncrement { get; set; }
        public string dataTypeName { get; set; }
        public int numericPrecision { get; set; }
        public int numericScale { get; set; }
    }

【问题讨论】:

  • 我错了,还是这三个类完全一样?为什么不对所有三个列表使用一个类?
  • 这些类是否以某种方式生成?它们是否可以从一个基类派生或至少实现相同的接口?
  • 这里不仅价值不同.. 整个合同也不同。
  • 我明白了。我现在明白了.. 假设我们有一个 1 类忽略 coliffTypes 和 coldiffTypesTarget 。因为他们有相同的对象,我可以比较 public List colDiffUpdated = new List();公共列表 colDiffTarget = new List();如果我使用 except 或 intersect 它返回 null ..

标签: c# compare listobject


【解决方案1】:

这些类看起来具有相同的属性,如果是这样,只需实现一个类 IEqualityComparer 并比较该类 colDiffUpdated 和 colDiffTarget 列表的每个值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 2015-01-26
    • 2017-09-20
    • 2012-03-25
    相关资源
    最近更新 更多