Learning to Find and Use What You Need

Learning to Find and Use What You Need

In this section, you'll learn how to find exactly what you need in the .NET Framework. Once you know how to find what you want, we'll take a hands-on approach to understand how to use any class within the framework, using file management classes as an example. This approach will permit you to understand and use every class in the framework. You will soon see that the .NET Framework is not only extremely powerful, but also easy to use once you understand it.

The Windows Class Viewer (WinCV tool) is helpful for locating what we are looking for in the .NET Framework. This tool is located in C:\Program Files\Microsoft VisualStudio .NET\FrameworkSDK\Bin\WinCV.exe.

tip

You'll want to have this tool available each and every time you program, so you can save some time by creating a shortcut to the program. You might want to place the shortcut on your desktop so that you can quickly start WinCV while you're programming Visual Basic .NET.

Start WinCV now. The program should appear as shown in Figure 5-1.

Figure 5-1

The WinCV tool.

Searching in Windows Class Viewer

One of the tasks that every programmer needs to do is read from and write to a file. Performing these operations in .NET is a bit different from how you did them in classic Visual Basic. Rather than just tell you how to do this, let's use the Socratic method with a little help from our friend WinCV.

We want to create a file and then read from and write to it. A programmer new to .NET would probably use the WinCV tool and type in the word File because that is what we want to work with. However, this search word causes WinCV to display a cornucopia of various and sundry classes in all sorts of namespaces, as shown in Figure 5-2. That amount of information might be disorienting to a Visual Basic .NET beginner. Where in the world would you start looking for what you need?

Figure 5-2

Searching on the word "file" causes WinCV to display a lot of information.

Many namespaces and classes within these namespaces contain the word file, so when we search on it, we get everything and the kitchen sink in return. While this search is the way many beginning programmers would try to find information about how to handle file access, notice that WinCV shows entries from namespaces such as System.Web.UI, System.Reflection, System.Net.File WebRequest, and many others. For each class in which the literal term file is found, an entry is displayed in the WinCV tool.

Using the Namespaces

Recall from Table 5-1 that the namespace System.IO contains file access classes. Try searching for System.IO instead of the word file, as shown in Figure 5-3. Notice that these classes look more like what we want.

Figure 5-3

Searching for "System.IO" reveals the classes we need.

The File class of System.IO contains various properties, methods, and events for creating, copying, moving, and deleting files. Select File in the Class Name column, and look at the information displayed in the Selected Class area. What we want to do now is fully understand exactly how to read and use this information.



Coding Techniques for Microsoft Visual Basic. NET
Coding Techniques for Microsoft Visual Basic .NET
ISBN: 0735612544
EAN: 2147483647
Year: 2002
Pages: 123
Authors: John Connell

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