Although we have not begun programming yet, we can still run on the enhancements and the Code Editor. Let us go ahead and double click on the FORM. This will launch us into the Code Editor. Let us examine some of the features that we have available. Hit the ENTER key a few times.
On the left hand part of your screen, there is a little yellow indicator bar. This yellow bar indicates the state of your code whether it has been saved or whether it has not been saved. Yellow indicates that my code is “dirty” meaning I need to save it. Once I hit CTRL+S, you can see the indicator now turns green. This indicates this change in my code has now been save to disk.
Code revision marks are new to Visual Studio 2005. If you start seeing a lot of yellow in your project, you know that it is time to save.
Another new feature in this Visual Studio 2005 and .Net2.0 is a concept called “REFACTORING.” Refactoring enables you to make changes to your code in bulk rather than one by one.
We are going to write some code. This example is actually a quadruple play of productivity enhancements for your code. You will not only see refactoring, you also see another example of smart task in action. You will see automatic code generation and the exception assistant. Navigate down to right end before the end class line. As you can see the code revision marks indicate that the code is dirty.
Let us create a new property. Type in PUBLIC PROPERTY 2 as a string. Now hit ENTER. The Visual Studio 2005 has automatically generated a code for me. It generates both the GET and a SET. The GET allows me to retrieve data from my property and the SET allows me to put data into my property. You can also see a green squiggly line. This indicates to me that I might have a problem with my code.
Let us go ahead and take a look at it. It is indicating that my GET is not returning a value. Let us go ahead and returns them a kind of value. Type in or turn HELLO, quick ENTER and you will see this squiggle now goes away.
Visual Studio 2005 ensures that you are following best practices with your code. Highlight the 2 lines of set code and now select DELETE. Now you will see underneath the fill, a blue squiggly line and a small rectangle have formed. Let us go and see what this means.
By deleting the set, my intentions were to only provide a read only property. That way, I can only get values out of the foo property and not set any values inside of it. However, the code indicator indicates to me that a property without a Read Only or a Write Only specifier must have both methods. So, what do I do? This is the exception assistant new to Visual Studio 2005.
Let us examine what options I have. I will see a smart task has now popped up. Here is a tip for you; another way to bring this task is by the keyboard shortcut SHIFT+ALT+S10, that way you do not have to fumble with the mouse.
You can see an exclamation point indicates that I have some error corrections options. Go and select the top down value. Now I have even more information about my exception. It indicates that a property without a Read Only or a Write Only specifiers has a couple of options I can do. One, is to go ahead and insert the missing set. I can see what that will look like. That will restore my code back to its original state. I want them to get rid of that set, so that is not an option for me.
Let us what other choices we have. Down here I can see that I can go ahead and insert the Read Only specifier and not have a set at all. This sound ideal to me, so go ahead and click on this hyperlink. What happens is the code automatically generates a Read Only property for me. I do not have to type a line or code and I can now guarantee my code is following best practices.
Now that I have my Read Only property, move over to your form one load event. Let us go ahead and call this property. To mention a new variable called mystring fill as string. Now let us go ahead and set that value to a property. As you can see already, a green squiggle has formed. If we can take a look what that means you will see that it is saying th
Transcription by:
Scribe4you Transcription Services