I saw some examples when they transformed a call like
void Add(IDrawing item);
in
void Add<TDrawing>(TDrawing item) where TDrawing : IDrawing;
Also, to convince intellisense to display the name of your class instead of the interface name when calling a function due to the use of the intended type in C # 4, is there any other advantage to using the second approach?
To answer Jon Skeet, the code our programmer uses is:
public ObservableCollection<IDrawing> Items { get; private set; } public void Add<TDrawing>(TDrawing item) where TDrawing : IDrawing { this.Items.Add(item); }
I see no advantage here in using the general, and not just using an IDrawing type IDrawing . I suppose there should be some case where it is very appropriate. I was curious to find out if something was missing.
generics c #
Pierre-alain vigeant
source share