Hi guys - I need your advice)
In which cases It'll be correct to use <T> after class name when I want to have generic type fileds in this class?
big thanks in advance)
vedro-compota
33
Posting Whiz
Recommended Answers
Jump to PostAre you talking about generic method?
If the operations performed by several overloaded methods are identical for each argument type, the overloaded methods can be more compactly and conveniently coded using a generic method. You can write a single generic method declaration that can be called at different times with …
Jump to PostDepends, if your return that type of not. If you do not return, then your method does not need to be a type of <T>, otherwise is has to be.
Example:static List<T> GetInitializedList<T>(T value, int count) { // This generic method returns a List with ten …
Jump to PostThat you can return T. Becuase the method is a return type of <T>. If there is no specific return type in the method name, you are unable to return it.
In your 2nd example you can return T vlaue, when in your 1st can not.
All 12 Replies
Mitja Bonca
557
Nearly a Posting Maven
vedro-compota
commented:
++++++
+1
vedro-compota
33
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
ddanbe
commented:
Good explanation.
+9
vedro-compota
33
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
vedro-compota
33
Posting Whiz
vedro-compota
33
Posting Whiz
Momerath
1,327
Nearly a Senior Poster
Featured Poster
vedro-compota
commented:
+++++
+3
vedro-compota
33
Posting Whiz
vedro-compota
33
Posting Whiz
Momerath
1,327
Nearly a Senior Poster
Featured Poster
vedro-compota
33
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.