Prev | Current Page 68 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Utilities
Dim c As Class1 = New Class1
The code is now easier to deal with and easier to read. You can only refer to a namespace in
an assembly that your project has a reference to. So if you want to use a type in the System.XML
namespace, you must first add a reference to System.Xml.dll because that??™s the assembly in
which the namespace is declared. Another namespace issue you might run into is having two
namespaces that each contain a class with the same name. This is perfectly legal because their
fully qualified names are unique. Let??™s say, for example, you have your own data access types
defined in a namespace called Acme.Data with a DataTable class, and you also use the
System.Data namespace that has a DataTable class:
Namespace Acme.Data
Public Class DataTable
End Class
End Namespace
CHAPTER 2 n VB 2008 SYNTAX 27
If you use the DataTable class, the compiler won??™t know which namespace you??™re referring
to and will throw an ambiguous name exception. In a case like this, you have two options. The
first is to use the fully qualified namespace name. The second is to assign an explicit alias to a
namespace, like this:
Imports System.Data
Imports db = Acme.Data
Anywhere you want to use the DataTable class in your own namespace, you just prefix the
class name with db, like this:
Dim c As db.


Pages:
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
projektowanie wnętrz gry strategie życzenia ślubne katalog stron katalog stron