English 中文(简体)
• 如何在通用类别中找到T论点,并交回另一种类型
原标题:How to Get T argument in generic class and return another type in Interface

我想使用这一法典:

List<U> SelectAll<T>() where T : class;

问题在于,我想通过T型和U型,但C#有关键词,但没有U关键词。 • 如何通过T型,在Interface declration>中找到另一种类型;

感谢


Sorry I post Answer here but I want show you code: I m writing this code:

interface IRepoitory<T> where T : class
{
    T CreateInstance();

    IEnumerable<U> SelectAll();

what can I write instead of "U"? when I Impelement interface and I have this code:

IEnumerable<TResult> SelectAll<TResult>();

In Class that implement the interface I cant Return Any class instead of TResult 感谢

问题回答

T is not a keyword in C# - it s just a conventional name for a type parameter. If you want to specify multiple type parameters, you can do so very easily:

public static List<U> SelectAll<T, U>() where T : class

(此处使用t> /code>的数据或数据方式不清楚。)

公约类型参数要么are T或start with T, 因此,您可能希望:

public static List<TResult> SelectAll<TResult>() where T : class

如果你能够澄清你试图做些什么,我们或许能够提供更多的帮助。

    public static List<TResult> SelectAll<T, TResult>(T inParam) where T: class
    {
        return new List<TResult>();
    }

你们是否想要? 如果你不知道结果的类型,你需要告诉方法汇编者返回的类型。 采用SelectAll<T, TResult>





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签