What's New in Visual Basic 14 for Visual Studio 2015

Let me start with the most trivial change that's also the one you'll use the most: Right now, you type in a line of code, get a squiggly line under something indicating that you've got an error, fix the error … and then arrow off the line to see if the squiggle goes away. In Visual Studio 2015 with Visual Basic 14, you won't have to move off the line to have the squiggle go away: It will just go away.

More

Posted by Peter Vogel on 05/20/20150 comments


My Favorite New Language Feature in C# 6.0 and Visual Basic 14

Both Visual Basic 14 and C# 6.0, developers get the NameOf operator/keyword. It doesn't do much: It returns the name of the variable or member passed to it. This means I can write properties that integrate with the INotifyPropertyChanged event with code like this:

Public Property CompanyName() As String 
  Get
    Return Me.companyNameValue
  End Get 
  Set
    Me.companyNameValue = value
    NotifyPropertyChanged(NameOf(CompanyName))
  End Set
End Property
More

Posted by Peter Vogel on 05/13/20150 comments


What's New in Visual Basic 14? String Interpolation and Multiline Literals

I love the String object's Format method. It's an unusual application where I'm not using it to build messages. (Long ago and far away, I used to use it to assemble SQL statements.) Typical code looks like this:

Me.txtErrorMessage.Text = 
  String.Format("You must be in {0} status to update {1}.", statusLevel, operationTarget)
More

Posted by Peter Vogel on 05/12/20150 comments


New in Visual C# 6.0, Visual Basic 14: New Null/Nothing Check

I don't know how many times I've written this code like this:

if (stringVariable != null)
{
  int x = stringVariable.Length;
}

In Visual Basic I'd write this:

If stringVariable IsNot Nothing then
  Dim x as Integer 
  x = stringVariable.Length
End If
More

Posted by Peter Vogel on 05/04/20150 comments


What's New in C# 6.0: Selecting Exceptions in a Try...Catch Block

Visual Basic developers can put conditions on a catch block in a try...catch to control which catch block is executed when an error occurs.

With C# 6.0, C# developers can now do the same by adding a if test to the catch statement. This example checks the error message associated with the Exception object's InnerException to decide which catch block to execute:

More

Posted by Peter Vogel on 04/23/20150 comments


What's New in C# 6.0: Initialize Properties Just Like Fields

Auto-implemented properties let you define a property in a single line of code:

  public string LastName { get; set; }

In C# 6.0, you can also initialize that property to some constant value in the same statement, like this:

  public string LastName { get; set; } = "Vogel";
More

Posted by Peter Vogel on 04/21/20150 comments


What's New in C# 6.0: Dictionary Initializers

I recently did a column about how to create a simple collection class. In that column, I discussed collection initializers which let you add items to a collection when the collection is instantiated. Here's a variation on the example I used in that column which loads two Customer objects into a List:

More

Posted by Peter Vogel on 04/14/20150 comments


When Indexes Are No Help

In an earlier tip I discussed how indexes can speed up processing. It's only fair that I also talk about when indexes don't help.

First: Because indexes don't always help but do always increase the time it takes to update a table (though usually by a negligible amount) you should always run a test. Before applying an index to a table, take a moment to run a query that you think your index will help run faster -- ideally, some query used in production. Run the query twice and measure how long the query takes to complete the second time. Then, after applying your index, run the query twice again and compare the results of the second run.

More

Posted by Peter Vogel on 04/03/20150 comments


Configuring for a Setup Project

Eventually, it comes time to transfer your project to the production or quality assurance (QA) computer. In theory, you should just need to copy some files to the other computer. In practice, it's a lot safer to create a setup project that packages up everything you need and unpackages it on the other computer.

More

Posted by Peter Vogel on 03/19/20150 comments


Omitting and Including Debug Code

I'm working on an application that allows users to retrieve and then filter/sort their data. The rules for filtering the data seem especially bizarre to me (there are actually two sets of filters) and the users keep piling on requirements.

Since I'm modifying existing code (and don't want to take the time to rip it all out and start over again) I've been including some code to print out useful information to the Output window that helps me debug problems. I don't want this code to go into production, of course, because it would slow the application down microscopically.

More

Posted by Peter Vogel on 03/11/20150 comments


Visual Studio in Full-Screen Mode

Even after you maximize Visual Studio's window you don't yet have the maximum space for working with code and the Visual Studio's visual designers. To get the maximum bit of screen real estate available, you can put your Visual Studio edit window in full-screen mode by selecting View | Full screen (or just pressing Shift+Alt+Enter). Full screen mode gets rid of the toolbars and all of your tool windows (Solution Explorer, the Toolbox, etc.); you get to keep the menu bar and the tabs for your open files (though the tabs' appearance is altered to take up less room).

More

Posted by Peter Vogel on 03/05/20150 comments


Leveraging Views in Entity Framework

A typical screen in your user interface probably combines data from several different tables. To handle that, I typically have my back-end processes generate Data Transfer Objects (DTOs) which combine data from several different tables. To load these DTOs with the data they need, I retrieve rows from multiple tables and pull selected columns from each table to populate the properties on my DTOs.

More

Posted by Peter Vogel on 02/25/20150 comments


Subscribe on YouTube