code_junkie

Why do C# and VB have Generics? What benefit do they provide? Generics, FTW

Nov 11th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. //Old and busted
  2. public abstract class Enum
  3. {
  4. public static object Parse(Type enumType, string value);
  5. }
  6. //To call it:
  7. MyEnum x = (MyEnum) Enum.Parse(typeof(MyEnum), someString);
  8.  
  9. //New and groovy
  10. public abstract class Enum
  11. {
  12. public static T Parse<T>(string value);
  13. }
  14.  
  15. //To call it:
  16. MyEnum x = Enum.Parse<MyEnum>(someString);
Add Comment
Please, Sign In to add comment