.NET Tips and Tricks

Blog archive

What's New in Visual Basic 14: Parameterless Constructors in Structures

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.

Here's an example of a Structure with a default parameter:

Structure ProcessData
   Private ErrorCount As Integer
   Sub New()
      ErrorCount = -1
   End Sub
End Structure

If you want to have your default constructor actually execute, however, you must use the New keyword. This code will call the constructor and set ErrorCount to -1:

Dim pd As New ProcessData

This code will not:

Dim pd As ProcessData

and it will still run. Nifty, right?

Posted by Peter Vogel on 06/18/2015


comments powered by Disqus

Featured

  • Linear Regression Using JavaScript

    Dr. James McCaffrey presents a complete end-to-end demonstration of linear regression using JavaScript. Linear regression is the simplest machine learning technique to predict a single numeric value, and a good way to establish baseline results for comparison with other more sophisticated regression techniques.

  • Creating Simple Chat Bots with Microsoft Fabric Datastores

    At Visual Studio Live! San Diego, Ginger Grant of Desert Isle Group will lead a practical, demo-driven session on how to build simple yet powerful chatbots using Microsoft Fabric lakehouses and warehouses. Attendees will learn how to use AI skills and grounding techniques to enable conversational data access -- quickly and cost-effectively. Ideal for developers ready to extend analytics with conversational interfaces.

  • Prompt Engineering? See VS Code Team's System Prompts for Copilot Chat, Now Open Source

    "Explore the codebase and learn how agent mode is implemented, what context is sent to LLMs, and how we engineer our prompts."

  • VS Code Goes Transparent as Open-Source AI Editor

    Microsoft has open sourced the GitHub Copilot Chat extension, marking a major step in turning VS Code into an open-source AI editor focused on transparency, collaboration, and community-driven development.

  • New Default Model for Visual Studio Copilot, So How Do You Choose?

    Along with a new default model, a new Consumptions panel in the IDE helps developers monitor their usage of the various models, paired with UI to help easily switch among models.

Subscribe on YouTube