日期:2014-05-20 浏览次数:20763 次
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication9 { public class B//class版本 { public int i; } class Program { static void Main(string[] args) { List<int> list = new List<int>(); List<B> listClass = new List<B>(); for (int i = 0; i < 10000; i++) { B b = new B(); b.i = i; list.Add(b.GetHashCode()); listClass.Add(b); } Console.WriteLine(list.Distinct().Count());//9999 Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication9 { public struct B//struct版本 { public int i; } class Program { static void Main(string[] args) { List<int> list = new List<int>(); List<B> listClass = new List<B>(); for (int i = 0; i < 10000; i++) { B b = new B(); b.i = i; list.Add(b.GetHashCode()); listClass.Add(b); } Console.WriteLine(list.Distinct().Count());//10000 Console.ReadKey(); } } }