> I'm having a problem that I'm quite sure is quite simple
> to solve but for some reason I just can get it to work.
>
> All I want to do is to create an interface such as the following:
>
> --------------------------------------------------------------
> ----------
> -----------------------------
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> public interface IDataManager
> {
> List<T> SelectData();
> int UpdateData(<T> objectToBeUpdated);
> bool InsertData(<T> objectToBeInserted);
> bool DeleteData(<T> objectToBeDeleted);
> }
>
> --------------------------------------------------------------
> ----------
> -----------------------------
Either do:
public interface IDataManager<T>
where T:..
{
List<T> SelectData();
int UpdateData(T objectToBeUpdated);
bool InsertData(T objectToBeInserted);
bool DeleteData(T objectToBeDeleted);
}
or do:
public interface IDataManager
{
List<T> SelectData<T>();
int UpdateData<T>(T objectToBeUpdated);
bool InsertData<T>(T objectToBeInserted);
bool DeleteData<T>(T objectToBeDeleted);
}
Though, if I were you, I'd stay away from generics in interfaces, or at
most use the second option. The reason for this is
that an interface can be implemented by multiple types, and if your code has to
work with the interface, the type of 'T' is often
unknown, so option 1 has a problem: at some point, T has to be declared
somewhere.
Interfaces offer you a different way of generic programming, if you mix
that with generics, you mitigate the generic program
ability of interfaces and at the same time make your code more complex than it
should be.
Frans
>
> According to all the documentation I've read, this shouldn't
> be a problem, but every time I try to compile, the following
> compile error is thrown:
>
> Error 1 The type or namespace name 'T' could not be found (are
> you missing a using directive or an assembly reference?)
>
>
> This is probably blatantly obvious for most of you but I just
> haven't find a way to solve the problem.
>
> I am assuming I have to tell the compiler that T will be a
> generic type but I haven't found a way of doing it and as all
> the documentation and examples I've seen don't mentione it,
> it makes me think it's something very obvious...(not for me though).
> What is it that I am missing?
>
> Is there a secret reference I should be adding?
> Maybe a secret using statement that I am missing?
>
>
> Any ideas?
>
>
> Thanks in advance,
> Yago Alvarado
>
> - -----------
> Marketing Magazine's Contact Centre Agency of the Year 2005
> Field Marketing Gold - DMA / Royal Mail Awards Best Overall
> Site - British Gas Outbound Sales Awards
>
> http://www.cpm-int.com
> - -----------
>
> _____________________________________________________________________
> This e-mail is confidential and is intended solely for the
> use of the individual or entity to whom it is addressed. If
> you are not the intended recipient and you have received this
> e-mail in error then any use, dissemination, forwarding,
> printing or co pying of this e-mail is strictly prohibited.
> You should contact the sender by return e-mail and delete and
> destroy all the information from your system. Any views or
> opinions presented are solely those of the author and do not
> necessarily represent tho se of CPM. This email does not
> form part of a legally binding agreement. We have taken
> precautions to minimise the risk of transmitting software
> viruses or trojans, but we advise that you carry out your own
> virus checks on any attachments to this mess age. We cannot
> accept liability for any loss or damage caused to your
> software, hardware or system.
>
> Please note that all messages sent to CPM are actively
> monitored for inappropriate material and/ or content.
>
> ===================================
> This list is hosted by DevelopMentor. http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
>
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com