How to Get T argument in generic class and return another type in Interface?

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 SelectAll() where T : class (It's not clear where the data's coming from or how T will be used here, admittedly. ) Conventionally type parameters either are T or start with T, so you might want: public static List SelectAll() where T : class If you can clarify what you're trying to do, we may be able to help more.

Thanks @Jon. I want a thing similar to Func delegate that pass a type to it and get a TResult. – Nima Jan 6 at 7:07 @Nima: Well you can create such a thing... but it's hard to give any more details without knowing more about the context.

If you could give a short but complete example of the situation you've already got, and what you're trying to do, that would really help. – Jon Skeet Jan 6 at 7:12 Consider I Have a table in My Database that Have 10 Columns. In SelectAll method I want to return just 6 columns.It requires that I create a class(My return Type) that cover this return type.

In my repository Interface what I can write to do this and can implement it to my DAL? Thanks – Nima Jan 6 at 8:29 @Nima: Normally you'd use an anonymous type for this... but it still isn't really clear what you're asking from a language point of view. Please provide more sample code.

– Jon Skeet Jan 6 at 9:27.

If you don't know the type of result, you need to tell method compiler what type to return. This is done using SelectAll.

When I Impelement interface and I have this code: IEnumerable SelectAll(); In Class that implement the interface I cant Return Any class instead of TResult thanks.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions