You can tell that the Visual Studio team recognizes the primary issue C# developers face: finding the matching bracket. That must be true because the most obvious way of finding "the other bracket" is built into the way code is displayed: When you put your cursor beside one bracket (open or close), both it and the matching bracket are highlighted (or, because the default color for the brackets is gray: lowlighted).
More
Posted by Peter Vogel on 08/19/20150 comments
Developers frequently want to ensure two strings are identical without having to worry if some characters are in uppercase in one string and the same characters are in lowercase in the other string. Frequently, you see developers using either ToUpper or ToLower to avoid the problem:
If Name.ToUpper = OtherName.ToUpper Then...
More
Posted by Peter Vogel on 08/12/20150 comments
The is keyword lets you check if a variable is pointing to an object of a particular class (or a class that inherits from some class). For example, the code in this if block only executes if CustomerVariable is pointing at an object of type Customer (or some class that inherits from Customer):
if (CustomerVariable is Customer)
{
...code to execute...
}
It works with interfaces, too:
if (CustomerVariable is ICustomer)
{
...code to execute ...
}
More
Posted by Peter Vogel on 08/04/20150 comments
I suspect I'm like most developers and keep Visual Studio open and maximized all day (in fact, I've written at least one tip about how to get even more room to edit code). But, I admit, sometimes I switch to other programs. And sometimes, when switching between windows isn't good enough, I need to see that other window beside my Visual Studio window.
More
Posted by Peter Vogel on 07/30/20150 comments
I admit it: I don't use the Watch window much. When I hit a breakpoint and want to know what the current value is in a variable that's near the breakpoint, I'll either type "?variableName" in the Immediate window or hover my mouse over the variable to have Visual Studio pop up a Data Tip with the variable name and value.
More
Posted by Peter Vogel on 07/23/20150 comments
Within an Action method, you'll sometimes realize that the processing you need is in some other Action method, often in the same controller. ASP.NET MVC provides a couple of ways of transferring control from one Action method to another one, but, sometimes, the simplest solution is just to call the other method. In those cases, it's worthwhile to remember that when you call the View method in ASP.NET MVC, you're not actually processing a View. The View method merely creates a ViewResult object that, when you return it to ASP.NET MVC, causes ASP.NET MVC to find the View and process it.
More
Posted by Peter Vogel on 07/15/20150 comments
In the bad old days of desktop applications, every form object in the world had a Dirty property that let you easily check to see if the user had made any changes to the data on the form. It's almost as easy with client-side code running in the Web browser, provided you use jQuery. This line finds every input tag and ties the tag's change event to a JavaScript function called flagChanges:
More
Posted by Peter Vogel on 07/07/20150 comments
In previous columns, I've discussed options in assembling your View from a set of partial Views. However, in all of those examples, I've been assembling a View on the server in response to a request from the client.
More
Posted by Peter Vogel on 06/30/20150 comments
While everyone using the .NET Framework creates Classes, not many developers create Structures. For those of you who are creating Structures, Visual Basic 14 has some good news for you: You can now give your structure a constructor that doesn't accept parameters (a default constructor). Formerly any constructor you added to a Structure had to accept at least one parameter.
More
Posted by Peter Vogel on 06/18/20150 comments
Years and years ago, I talked about how interfaces and inheritance were tools for making different objects look alike. Using interfaces and inheritance this way allows you to process a heterogeneous group of objects using a single variable.
More
Posted by Peter Vogel on 06/11/20150 comments
I'm not a big fan of commenting code, which means that when I feel the need to add a comment it's because I feel that the comment is critical to the code's future. As a result, I want any comments I add to have maximum impact/usefulness.
In Visual Basic, however, I can only put comments before or after the statements that I want to comment. This is especially limiting in LINQ queries, which I often break up over multiple lines, putting each LINQ clause on a different line. This means that a comment on the line before the LINQ query may be explaining something three or four lines farther down the screen.
More
Posted by Peter Vogel on 06/09/20150 comments
In Visual Basic 14, can now have read-only auto-implemented properties: Just add the ReadOnly keyword to the Property declaration. Here's an example:
Class Customer
Public ReadOnly Property Id As String
You can set the property by name from within your class' constructors. This example sets my Customer's Id property:
More
Posted by Peter Vogel on 05/29/20150 comments