<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLINQ%2FDistinct</id>
		<title>Csharp/CSharp Tutorial/LINQ/Distinct - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLINQ%2FDistinct"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/LINQ/Distinct&amp;action=history"/>
		<updated>2026-04-30T01:39:41Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/LINQ/Distinct&amp;diff=6184&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/LINQ/Distinct&amp;diff=6184&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/LINQ/Distinct&amp;diff=6185&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/LINQ/Distinct&amp;diff=6185&amp;oldid=prev"/>
				<updated>2010-05-26T12:18:29Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Distinct Operator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        string[] presidents = {&amp;quot;Grant&amp;quot;, &amp;quot;Harding&amp;quot;, &amp;quot;Harrison&amp;quot;, &amp;quot;Hayes&amp;quot;, &amp;quot;Hoover&amp;quot;, &amp;quot;Jackson&amp;quot;};&lt;br /&gt;
        Console.WriteLine(&amp;quot;presidents count:  &amp;quot; + presidents.Count());&lt;br /&gt;
        IEnumerable&amp;lt;string&amp;gt; presidentsWithDupes = presidents.Concat(presidents);&lt;br /&gt;
        Console.WriteLine(&amp;quot;presidentsWithDupes count:  &amp;quot; + presidentsWithDupes.Count());&lt;br /&gt;
        IEnumerable&amp;lt;string&amp;gt; presidentsDistinct = presidentsWithDupes.Distinct();&lt;br /&gt;
        Console.WriteLine(&amp;quot;presidentsDistinct count:  &amp;quot; + presidentsDistinct.Count());&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get all Make and don&amp;quot;t show duplicates==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Xml.Linq;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
    class Car&lt;br /&gt;
    {&lt;br /&gt;
        public string PetName;&lt;br /&gt;
        public string Color;&lt;br /&gt;
        public int Speed;&lt;br /&gt;
        public string Make;&lt;br /&gt;
        &lt;br /&gt;
        public override string ToString()&lt;br /&gt;
        {&lt;br /&gt;
            return string.Format(&amp;quot;Make={0}, Color={1}, Speed={2}, PetName={3}&amp;quot;,Make, Color, Speed, PetName);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Car[] myCars = new []{&lt;br /&gt;
                new Car{ PetName = &amp;quot;A&amp;quot;, Color = &amp;quot;Silver&amp;quot;, Speed = 100, Make = &amp;quot;BMW&amp;quot;},&lt;br /&gt;
                new Car{ PetName = &amp;quot;B&amp;quot;, Color = &amp;quot;Black&amp;quot;, Speed = 55, Make = &amp;quot;VW&amp;quot;},&lt;br /&gt;
                new Car{ PetName = &amp;quot;C&amp;quot;, Color = &amp;quot;White&amp;quot;, Speed = 43, Make = &amp;quot;Ford&amp;quot;}&lt;br /&gt;
            };&lt;br /&gt;
        &lt;br /&gt;
            var makes = from c in myCars select c.Make;&lt;br /&gt;
            foreach (var m in makes.Distinct&amp;lt;string&amp;gt;())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Make: {0}&amp;quot;, m);&lt;br /&gt;
            }&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get Distinct departments==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class Tree&amp;lt;TreeNode&amp;gt; : IEnumerable&amp;lt;TreeNode&amp;gt; where TreeNode : IComparable&amp;lt;TreeNode&amp;gt; {&lt;br /&gt;
    public Tree(TreeNode nodeValue) {&lt;br /&gt;
        this.NodeData = nodeValue;&lt;br /&gt;
        this.LeftTree = null;&lt;br /&gt;
        this.RightTree = null;&lt;br /&gt;
    }&lt;br /&gt;
    public void Insert(TreeNode newItem) {&lt;br /&gt;
        TreeNode currentNodeValue = this.NodeData;&lt;br /&gt;
        if (currentNodeValue.rupareTo(newItem) &amp;gt; 0) {&lt;br /&gt;
            if (this.LeftTree == null) {&lt;br /&gt;
                this.LeftTree = new Tree&amp;lt;TreeNode&amp;gt;(newItem);&lt;br /&gt;
            } else {&lt;br /&gt;
                this.LeftTree.Insert(newItem);&lt;br /&gt;
            }&lt;br /&gt;
        } else {&lt;br /&gt;
            if (this.RightTree == null) {&lt;br /&gt;
                this.RightTree = new Tree&amp;lt;TreeNode&amp;gt;(newItem);&lt;br /&gt;
            } else {&lt;br /&gt;
                this.RightTree.Insert(newItem);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void WalkTree() {&lt;br /&gt;
        if (this.LeftTree != null) {&lt;br /&gt;
            this.LeftTree.WalkTree();&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(this.NodeData.ToString());&lt;br /&gt;
        if (this.RightTree != null) {&lt;br /&gt;
            this.RightTree.WalkTree();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public TreeNode NodeData { get; set; }&lt;br /&gt;
    public Tree&amp;lt;TreeNode&amp;gt; LeftTree { get; set; }&lt;br /&gt;
    public Tree&amp;lt;TreeNode&amp;gt; RightTree { get; set; }&lt;br /&gt;
&lt;br /&gt;
    IEnumerator&amp;lt;TreeNode&amp;gt; IEnumerable&amp;lt;TreeNode&amp;gt;.GetEnumerator() {&lt;br /&gt;
        if (this.LeftTree != null) {&lt;br /&gt;
            foreach (TreeNode item in this.LeftTree) {&lt;br /&gt;
                yield return item;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        yield return this.NodeData;&lt;br /&gt;
        if (this.RightTree != null) {&lt;br /&gt;
            foreach (TreeNode item in this.RightTree) {&lt;br /&gt;
                yield return item;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {&lt;br /&gt;
        throw new NotImplementedException();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Employee : IComparable&amp;lt;Employee&amp;gt; {&lt;br /&gt;
    public string FirstName { get; set; }&lt;br /&gt;
    public string LastName { get; set; }&lt;br /&gt;
    public string Department { get; set; }&lt;br /&gt;
    public int Id { get; set; }&lt;br /&gt;
    public override string ToString() {&lt;br /&gt;
        return String.Format(&amp;quot;Id: {0}, Name: {1} {2}, Dept: {3}&amp;quot;, this.Id, this.FirstName, this.LastName, this.Department);&lt;br /&gt;
    }&lt;br /&gt;
    int IComparable&amp;lt;Employee&amp;gt;.rupareTo(Employee other) {&lt;br /&gt;
        if (other == null)&lt;br /&gt;
            return 1;&lt;br /&gt;
        if (this.Id &amp;gt; other.Id)&lt;br /&gt;
            return 1;&lt;br /&gt;
        if (this.Id &amp;lt; other.Id)&lt;br /&gt;
            return -1;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Program {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Tree&amp;lt;Employee&amp;gt; empTree = new Tree&amp;lt;Employee&amp;gt;(new Employee { Id = 1, FirstName = &amp;quot;Janet&amp;quot;, LastName = &amp;quot;Gates&amp;quot;, Department = &amp;quot;IT&amp;quot; });&lt;br /&gt;
        empTree.Insert(new Employee { Id = 2, FirstName = &amp;quot;O&amp;quot;, LastName = &amp;quot;G&amp;quot;, Department = &amp;quot;Marketing&amp;quot; });&lt;br /&gt;
        empTree.Insert(new Employee { Id = 4, FirstName = &amp;quot;K&amp;quot;, LastName = &amp;quot;H&amp;quot;, Department = &amp;quot;IT&amp;quot; });&lt;br /&gt;
        empTree.Insert(new Employee { Id = 6, FirstName = &amp;quot;L&amp;quot;, LastName = &amp;quot;H&amp;quot;, Department = &amp;quot;Sales&amp;quot; });&lt;br /&gt;
        empTree.Insert(new Employee { Id = 3, FirstName = &amp;quot;E&amp;quot;, LastName = &amp;quot;L&amp;quot;, Department = &amp;quot;Sales&amp;quot; });&lt;br /&gt;
        empTree.Insert(new Employee { Id = 5, FirstName = &amp;quot;D&amp;quot;, LastName = &amp;quot;L&amp;quot;, Department = &amp;quot;Marketing&amp;quot; });&lt;br /&gt;
        var depts = (from d in empTree select d.Department).Distinct();&lt;br /&gt;
        foreach (var dept in depts)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Department: {0}&amp;quot;, dept);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Printing the unique Category names==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        List&amp;lt;Product&amp;gt; products = GetProductList(); var categoryNames = (&lt;br /&gt;
             from p in products&lt;br /&gt;
             select p.Category)&lt;br /&gt;
             .Distinct();&lt;br /&gt;
        Console.WriteLine(&amp;quot;Category names:&amp;quot;);&lt;br /&gt;
        foreach (var n in categoryNames) {&lt;br /&gt;
            Console.WriteLine(n);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    static List&amp;lt;Product&amp;gt; GetProductList() {&lt;br /&gt;
        List&amp;lt;Product&amp;gt; empTree = new List&amp;lt;Product&amp;gt;();&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;A&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 12, UnitsInStock = 5, Total = 36, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;B&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 2, UnitsInStock = 4, Total = 35, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;C&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 112, UnitsInStock = 3, Total = 34, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;D&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 112, UnitsInStock = 0, Total = 33, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;E&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 1112, UnitsInStock = 2, Total = 32, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        empTree.Add(new Product { ProductName = &amp;quot;F&amp;quot;, Category = &amp;quot;O&amp;quot;, UnitPrice = 11112, UnitsInStock = 0, Total = 31, OrderDate = new DateTime(2005, 1, 1), Id = 1 });&lt;br /&gt;
        return empTree;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Product : IComparable&amp;lt;Product&amp;gt; {&lt;br /&gt;
    public string ProductName { get; set; }&lt;br /&gt;
    public string Category { get; set; }&lt;br /&gt;
    public int UnitPrice { get; set; }&lt;br /&gt;
    public int UnitsInStock { get; set; }&lt;br /&gt;
    public int Total { get; set; }&lt;br /&gt;
    public DateTime OrderDate { get; set; }&lt;br /&gt;
    public int Id { get; set; }&lt;br /&gt;
    public override string ToString() {&lt;br /&gt;
        return String.Format(&amp;quot;Id: {0}, Name: {1} , Category: {3}&amp;quot;, this.Id, this.ProductName, this.Category);&lt;br /&gt;
    }&lt;br /&gt;
    int IComparable&amp;lt;Product&amp;gt;.rupareTo(Product other) {&lt;br /&gt;
        if (other == null)&lt;br /&gt;
            return 1;&lt;br /&gt;
        if (this.Id &amp;gt; other.Id)&lt;br /&gt;
            return 1;&lt;br /&gt;
        if (this.Id &amp;lt; other.Id)&lt;br /&gt;
            return -1;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Set Operators: Distinct==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        int[] fl = { 2, 2, 3, 5, 5 };&lt;br /&gt;
        var uniqueFactors = fl.Distinct();&lt;br /&gt;
        Console.WriteLine(&amp;quot;Prime factors of 300:&amp;quot;);&lt;br /&gt;
        foreach (var f in uniqueFactors) {&lt;br /&gt;
            Console.WriteLine(f);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Linq Distinct to get the distinct value in an array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
   public static void Main(){&lt;br /&gt;
            int[] numbers = {1, 1, 2, 3, 3};&lt;br /&gt;
            Console.Write(numbers.Distinct());&lt;br /&gt;
   }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>