Matthias Heise wrote:
By the way.
If you use your class that implements the IList interface later within a
foreach loop - the non-generic Enumerator is called. If you need the
generic one you must cast:
Hi Matthias,
I dont't think that this is correct! The example below always uses the
generic version:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
StringList myList = new StringList();
foreach (string str in myList)
{
// uses generic enumerator!!
}
foreach (string str in (IEnumerable<string>)myList)
{
// uses generic enumerator!! cast not necessary
}
}
}
class StringList : IList<string>
{
IEnumerator<stringIEnumerable<string>.GetEnumerato r()
{
Debug.Assert(false, "IEnumerable<string>.GetEnumerator()");
// Dummy call to get sample running
return new List<string>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
Debug.Assert(false, "IEnumerable.GetEnumerator()");
// Dummy call to get sample running
return new List<string>().GetEnumerator();
}
public void Add(string item)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(string item)
{
throw new NotImplementedException();
}
public void CopyTo(string[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public bool Remove(string item)
{
throw new NotImplementedException();
}
public int Count
{
get { throw new NotImplementedException(); }
}
public bool IsReadOnly
{
get { throw new NotImplementedException(); }
}
public int IndexOf(string item)
{
throw new NotImplementedException();
}
public void Insert(int index, string item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
public string this[int index]
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
}
Cheers,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm