<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>IComparable example to sort array elements</Title>
      <Shortcut>IComparableexampletosortarrayelements</Shortcut>
      <Description>IComparable example to sort array elements [C#]</Description>
      <Author>Zepho Zep</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=f10b4530-c7e6-4e45-9603-fad39f319859</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[using System;  
class Employee:IComparable 
{ 
  private int Id; 
  private string Name;  
  public Employee(int id,string name) 
  { 
    this.Id=id; 
    this.Name=name; 
  } 
  public int CompareTo(object obj) 
  { 
    Employee temp=(Employee)obj; 
     if(this.Id>temp.Id) 
    { 
      return 1; 
    } 
    else 
    { 
      if(temp.Id==this.Id) 
        return 0; 
      else 
        return -1; 
    } 
  }
//Sample usage
  public static void Main() 
  { 
    Employee[] employees=new Employee[5]; 
    Console.WriteLine("Before Sort:\n"); 
     for(int i=0;i<employees.Length;i++) 
    { 
      employees[i]=new Employee(5-i,"Employee#" + i); 
      Console.Write(employees[i].Id + ","); 
    } 
    Console.WriteLine(); 
    Array.Sort(employees); 
    Console.WriteLine("After Sort:\n"); 
     for(int i=0;i<employees.Length;i++) 
    { 
      Console.Write(employees[i].Id + ","); 
    } 
    Console.WriteLine(); 
  } 
}]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>