Linked Questions

20 votes
3 answers
9k views

I've noticed that the C# compiler doesn't infer second generic parameter. Example: C++ template code: (yea I know that templates don't work like generics) class Test { public: template <class T,...
Yochai Timmer's user avatar
5 votes
1 answer
2k views

The code below does not compile: public static class MyExtensions { public static Bar<M> Convert<T,M>(this Foo<T> list) { return new Bar<M>(); ...
emregon's user avatar
  • 418
0 votes
1 answer
270 views

I am writing a generic repository for C# and Entity Framework and I am trying to get this code to work without adding a whole bunch of extra interfaces. Essentially, I have a class called ...
philkills's user avatar
3 votes
0 answers
190 views

I want to define a generic base class for entities within a system that exposes the type of the entity's identifier (e.g. int, Guid, etc.) class Entity<TId> { } class Product : Entity<int&...
desmondgc's user avatar
  • 614
1 vote
0 answers
111 views

I made a generic Repository class with a GetById method public interface IEntity<T> { public T Id { get; set; } } ... public Product: IEntity<int> { public int Id { get; set; } } .....
Rodrigo's user avatar
  • 19
0 votes
1 answer
71 views

With regard to the following extension methods: public static class Extensions { public static void P<T>(this T value) { } public static TResult F<T, TResult>(this T value) { ...
David Arno's user avatar
  • 43.4k
1 vote
0 answers
57 views

I'd like to be able to do this: class IntMyClass : MyClass<int> { } class StringMyClass : MyClass<string> { } class FloatFloatMyClass : MyClass<float, float> { } class Container<T,...
helaj80024's user avatar
0 votes
0 answers
52 views

Say i want to do something like this T1 GenericMethod<T1>(T2 arg) where T1 : GenericClass<T2> { ... } seems it isn't possible, i have to write like this T1 GenericMethod<T1, ...
Ilya Mihalin's user avatar
0 votes
0 answers
26 views

Let's say I have the following classes: public class Class1<T> where T : SubClass1, new() { public T Item { get; protected set; } public Class1() { Item = new T(); ...
Greg's user avatar
  • 1,733
0 votes
0 answers
23 views

Hi I was curious if there's an easy way to retrieve nested generics from a given type. For example say I have: public class Token<T, V> { protected readonly T fieldT; protected readonly ...
Ian's user avatar
  • 331
1 vote
2 answers
210 views

I'd like the compiler to infer a type for me, but am unsure if it is possible, or what the best alternative might be. I'd like to do: public static TValue Get<TValue>(TKey key) where TValue : ...
Charles W's user avatar
  • 2,292
3 votes
3 answers
143 views

I want to create a wrapper function for a generic class like so: public class ColumnData { public static ColumnData<T> Create<T>(string name, int width, ColumnType type, ...
Bobson's user avatar
  • 13.7k
1 vote
1 answer
399 views

I have a such code: class A<T> { } class B : A<int> { } class C<T1, T2> where T1 : A<T2> { } But when I want to instantiate the C class with B as first generic type I ...
Zakhar Kurasov's user avatar