Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In Visual Studio 2010 Essential Training, author Walt Ritscher demonstrates how to use Visual Studio 2010 Professional to develop full-featured applications targeting a variety of platforms. Starting with an overview of the integrated developer environment, the course covers working with code editors, navigating and formatting code, and deploying applications. Also included are tutorials on running performance and load tests, and debugging code. Exercise files accompany the course.
Classes and structures are the heart of building an object-oriented application. When you are creating these classes, you can use a tool called Class Designer to simplify integration tasks. If you are looking at existing classes, you navigate through your class structure with the Object Browser or the Class View. Let's start by looking at the Class View. I am inside Visual Studio, and I have opened a project called UsingClassWindows. You can see I have two folders in here that contain classes. I have a BookSeller folder, which contains five classes, and a DataServices folder, which contains this DataShuttle class.
I can investigate my class structure by using the Class View. To View the Class View, I go to the View menu and then choose Class View. It lives over here next to the Solution Explorer. It's usually a tab on the same area of the screen as the Solution Explorer. If you look at the top of this Class View, you'll see three different namespaces. The first namespace contains one class, my console program class. The second namespace, the BookSeller namespace, contains these five classes I showed you, and then this last namespace here contains one class.
Now if I double-click on one of these classes, it takes me over to the source code. I am thinking that I put this class in the wrong namespace, so what I can do is come up here and edit my code, and say this belongs in the BookSeller namespace. And after a few seconds, when you look over in the Class View, you'll see that the third namespace is disappeared. And now if I expand this section, you'll see that the DataShuttle is now part of the BookSeller namespace. The Object Viewer is another way to View the classes and their members. The difference between the Object Viewer and the Class View is that the Object Viewer provides a drilldown into the objects in any reference .NET assembly, not just the ones that you have written.
Again, I am going to return to the View menu. This time I'll choose the Object Browser. It lives in the center of the screen. This shows all of the reference namespaces that I have in my project. I can search for something like, say the Console window, and once I find the type that I am interested in, I can click on it and in this section of the screen, I can see all of its members. There are all the methods that are part of System.Console, and here are all of the properties. When I click on one of these properties, I can read about it down here in this bottom section. Same with the methods.
So it's another way of examining the classes that somebody else has written. Very handy. The Class Designer exists to make it simple to diagram and model your classes. It provides a visual representation of your classes and the relationships with other entities. It also provides a way of modifying those classes. Here is how you create a Class Diagram. You find one of your types, say this Book class. Before I go any further, let me close this Object Browser. Close that window. Right-click on this Book. This time I am in the Class View, and I will choose View Class Diagram.
What you see is a visual representation of your class, the structure of your class, not the code itself, but the structure of this class. I can click on these little chevrons here, and see the Properties on my type. I can also, on the bottom of the screen see the methods, properties, and fields that are part of this type. An alternative way of adding a Class Diagram is to go to your solution, right-click on your project, choose Add > New item, type in the word "class" here in the Filter box, and then pick this Class Diagram. That adds this file here, BookSellerDiagram.cd.
That ClassDiagram1.cd was created when I right-clicked on the book class and told it to view the Class Diagram. Now let's look and see what it says here. "The Class Designer allows you to visualize and work with types in your code. Create new types by dragging items from the Toolbox." If you go over and open your Toolbox-- you may not see it on your screen, but you can go to View, Toolbox-- here is a listing of the things I can create. I am going to come back and show you how to use that in just a minute. It also says you can, "visualize the existing types by dragging items from the Class View or Solution." That implies I can take this book, and drag it over and drop it on the surface, and then I could take this Person class and this Employee class and drag those over.
Because the Employee and the Person Class have a object relationship, the diagram shows this relationship arrow. If I double-click on the Employee model, I can see that Employee derives from Person. I can use the Class Diagram to diagram other classes that aren't part of my project. To do that, I need to go over to my Class View, and then up here in the Search dialog, I'll type the name of a namespace or type that exists in one of the .NET assemblies. For instance, I am going to look at System.IO. Now, I'll slide these over and make some room.
I'll open the System.IO namespace, and then I am going to take this File class and drag it over, or this Stream class and drag that over. And then I can click on this dropdown to learn more about the type, and I can see its methods and other details in the bottom of the screen. Let me switch back to this ClassDiagram1 that was generated earlier today. I am supposed to be able to go over to the Toolbox and pick up one of these items over here-- this Interface, or this Class, or this Delegate, and these Inheritance arrows--and I am supposed to be able to take these and drag them over to my designer surface.
When I drag the Class over, it says, what kind of class would you like to create? I think I'll create a Customer class. It's going to go in this file, Customer.cs. Then I can come down to this bottom section and add Methods, like the Save method. Or I can add a property, FirstName, and so on. And if you double-click on this model, it takes you over to where the code is being generated, and I can see that it created a class with this property and this Save method. So let's review what we have seen. If you want to look at objects in compiled assemblies, use the Object Browser.
If you want to examine or modify the classes in your own code, use the Class View or the Class Designer.
Find answers to the most frequently asked questions about Visual Studio 2010 Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.