I want to create an extension method with generics. But when using this method I get the error Compiler Error CS0311. How can I solve this? Here's an example.
using Compare;
using System.Collections.ObjectModel;
static class Program
{
static void Main()
{
var OldItemListe = new LoadListe();
var NewItemListe = new LoadListe();
bool ReturnValue = new Import().Compare(OldItemListe, NewItemListe); //Here I got the Error CS0311
}
}
namespace Compare
{
/// <summary>Baseclass for all Elements </summary>
public class BaseClass
{
/// <summary> Elementname </summary>
public string Name { get; set; }
/// <summary> Beschreibung </summary>
public string Description { get; set; }
}
public abstract class BaseListe<T> : Collection<T> where T : BaseClass, new() { }
public class Load : BaseClass{}
public sealed class LoadListe : BaseListe<Load> {}
public class Import
{
public bool Compare<U>(U OldItemListe, U NewItemListe) where U : BaseListe<BaseClass>
{
// do something
if (OldItemListe[1].Name == NewItemListe[1].Name) return true; // only Example
return false;
}
}
}