C#新手 如何得到列表A有列表B无的元素列表

偏爱风流 偏爱风流 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;

namespace CompareUtility
{

struct Item
{
int id;
int size;
}

public class Compare
{
List<Item> lstA = new List<Item>();
List<Item> lstB = new List<Item>();

public void Init()
{
//好像下面不能这样增加元素
lstA.Add(new Item() { 1, 10 });
lstA.Add(new Item() { 2,10});
lstA.Add(new Item() { 3, 10 });
lstA.Add(new Item() { 4, 10 });
lstB.Add(new Item() { 1, 10 });
lstB.Add(new Item() { 2, 10 });
lstB.Add(new Item() { 3, 10 });
lstB.Add(new Item() { 5, 10 });
}
//比较新增 即B有 A无
public List<Item> CompareAdd()
{
//var lst = lstB.Except(lstA);
//return lst;
//求方法
}

//比较相同 即A和B都有的
public List<Item> CompareSome()
{
//求 方法
}
}
}
...全文

相关推荐

C#查找列表中所有重复出现元素的方法

主要介绍了C#查找列表中所有重复出现元素的方法,涉及C#针对列表操作的技巧,非常具有实用价值,需要的朋友可以参考下

weixin_38568031

C#在foreach遍历删除集合中元素的三种实现方法

主要给大家总结介绍了关于C#在foreach遍历删除集合中元素的实现方法,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧

weixin_38621104

C#使用linq计算执行元素在列表中出现次数的方法

本文实例讲述了C#使用linq计算执行元素在列表中出现次数的方法。分享给大家供大家参考。具体如下: 这是使用linq计算元素在列表中出现的次数,调用方法非常简单,和sql语句很像 代码如下:// Count the number of times an item appears in this list public static int CountTimes&lt;T&gt;(this List&lt;T&gt; inputList, T searchItem) { return ((from t in inputList where t.Equals(searchItem) select t).Count())

weixin_38653694

C# 判断两个列表(集合) 是否一致

C# 判断两个列表(集合) 是否一致 public static Class CollectionHelper{ /// &lt;summary&gt; /// 判断两个集合是否相等 /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt; /// &lt;param name="sourceCollection"&gt;源列表&

龟速学习

C#实现AddRange为数组添加多个元素的方法

主要介绍了C#实现AddRange为数组添加多个元素的方法,实例分析了AddRange方法的使用技巧,需要的朋友可以参考下

weixin_38742453
评论 3
收藏 已收藏
分享
返回顶部
偏爱风流
C# 111,129 成员 642,538 内容