Returns the index of the first occurrence in a sequence by using the default equality comparer. : IComparable « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Collections Data Structure » IComparableScreenshots 
Returns the index of the first occurrence in a sequence by using the default equality comparer.
 
//The MIT License (MIT)
//http://arolibraries.codeplex.com/license

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace AroLibraries.ExtensionMethods.Enumerable
{
    public static class IEnumerableExt
    {

        /// <summary> Returns the index of the first occurrence in a sequence by using aspecified IEqualityComparer. 
        /// </summary> ///
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="list">A sequence in which to locate a value.</param> ///
        ///  <param name="value">The object to locate in the sequence</param> /// <param name="comparer">An equality comparer to compare values.</param> 
        /// <returns>The zero-based index of the first occurrence of value within the entire sequence, if found; otherwise, –1.</returns>
        public static int Ext_IndexOf<TSource>(this IEnumerable<TSource> list, TSource value, IEqualityComparer<TSource> comparer)
        {
            int index = 0;
            foreach (var item in list)
            {
                if (comparer.Equals(item, value))
                {
                    return index;
                }
                index++;
            }
            return -1;
        }
        /// <summary>  Returns the index of the first occurrence in a sequence by using the default equality comparer. 
        ///</summary> 
        /// <typeparam name="TSource">The type of the elements of source.</typeparam> 
        /// <param name="list">A sequence in which to locate a value.</param> 
        /// <param name="value">The object to locate in the sequence</param> 
        /// <returns>The zero-based index of the first occurrence of value within the entire sequence, if found; otherwise, –1.</returns>
        public static int Ext_IndexOf<TSource>(this IEnumerable<TSource> list, TSource value)
            where TSource : IEquatable<TSource>
        {
            return list.Ext_IndexOf<TSource>(value, EqualityComparer<TSource>.Default);
        }
    }
}

   
  
Related examples in the same category
1.Creates and accesses an array of classes. Implements the IComparable interfaceCreates and accesses an array of classes. Implements the IComparable interface
2.Returns the index of the first occurrence in a sequence by using a specified IEqualityComparer.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.