Uses for C# generics besides collections -


i read on msdn generics useful creating collections. pretty new c# , wondering if there cases of when use generics purposes other collections. if there provide example illustrate argument.

generics feature major aims promote code reuse , type safety, concepts applicable broader segment of code collections.

it easy see code reuse , type safety go hand-in-hand collections: linq uses generics provide algorithms can operate on type of enumerable sequence (code reuse) , various generic collection classes use generic type information provide type safety (e.g. program trying add int list<string> not compile).

that said, there many more opportunities leverage generics. example, factory can use generics type safety:

class factory {     // can create type of widget, not allow e.g. create<string>()     public widget create<t>() t: widget { ... } } 

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -