H
Hoop
Hi,
I am in the process of trying to create a Generic Class. Getting a
complier error that I am not sure how to deal with.
Here is the class:
using System;
using System.Collections.Generic;
using System.Text;
using DeviceInterface;
using CanDevice;
using CanInterface;
namespace SimulatorApplication
{
//Generic class to store CanDevice's
class CanDeviceCollection<T> : IEnumerable<T>
{
private List<T> arDevices = new List<T>();
//A generic method just to display the data
public static void DisplayBaseClass()
{
Console.WriteLine("Base class of {0} is: {1}.",
typeof(T), typeof(T).BaseType);
}
public T GetDevice(int pos)
{ return arDevices[pos]; }
public void AddDevice(T d)
{ arDevices.Add(d); }
public void ClearDevice()
{ arDevices.Clear(); }
public int Count
{ get { return arDevices.Count; } }
// IEnumerable<T> extends IEnumerable, therefore
// we need to implement both versions of GetEnumerator().
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{ return arDevices.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() //Compiler Error Here
{ return arDevices.GetEnumerator(); }
}
}
I get the error, Using generic type
'System.Collections.Generic.IEnumerator<T> 'requires '1' type
arguments.
I have followed an example from the text "Pro C# 2005 and the .NET 2.0
Platform" for this code.
Any help or direction would be appreciated.
Thanks
Jeff
I am in the process of trying to create a Generic Class. Getting a
complier error that I am not sure how to deal with.
Here is the class:
using System;
using System.Collections.Generic;
using System.Text;
using DeviceInterface;
using CanDevice;
using CanInterface;
namespace SimulatorApplication
{
//Generic class to store CanDevice's
class CanDeviceCollection<T> : IEnumerable<T>
{
private List<T> arDevices = new List<T>();
//A generic method just to display the data
public static void DisplayBaseClass()
{
Console.WriteLine("Base class of {0} is: {1}.",
typeof(T), typeof(T).BaseType);
}
public T GetDevice(int pos)
{ return arDevices[pos]; }
public void AddDevice(T d)
{ arDevices.Add(d); }
public void ClearDevice()
{ arDevices.Clear(); }
public int Count
{ get { return arDevices.Count; } }
// IEnumerable<T> extends IEnumerable, therefore
// we need to implement both versions of GetEnumerator().
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{ return arDevices.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() //Compiler Error Here
{ return arDevices.GetEnumerator(); }
}
}
I get the error, Using generic type
'System.Collections.Generic.IEnumerator<T> 'requires '1' type
arguments.
I have followed an example from the text "Pro C# 2005 and the .NET 2.0
Platform" for this code.
Any help or direction would be appreciated.
Thanks
Jeff