Section 25.8. Wrap-Up


25.8. Wrap-Up

This chapter introduced genericsone of Visual Basic's newest capabilities. We discussed how generics ensure compile-time type safety by checking for type mismatches at compile time. You learned that the compiler will allow generic code to compile only if all the operations performed on the type parameters in the generic code are supported for all the types that could be used with the generic code. You also learned how to declare generic methods and classes using type parameters. We demonstrated how to use a type constraint to specify the requirements for a type parametera key component of compile-time type safety. We discussed several kinds of type constraints, including reference type constraints, value type constraints, class constraints, interface constraints and New constraints. You learned that a New constraint indicates that the type argument's class must be concrete and must provide a Public parameterless or default constructor so that objects of that type can be created with New. We also discussed how to implement multiple type constraints for a type parameter. We showed how generics improve code reuse. Finally, we mentioned several ways to use generics in inheritance. In the next chapter, we demonstrate the FCL's collection classes, interfaces and algorithms. Collection classes are pre-built data structures that you can reuse in your applications, saving you time. We present both generic collections and the older, non-generic collections.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net