Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 343901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:56:26+00:00 2026-05-12T10:56:26+00:00

In a recent VB.NET project I adopted the naming conventions I’m used to using

  • 0

In a recent VB.NET project I adopted the naming conventions I’m used to using in C#. Namely, often calling a variable the same name as the class it references, only with a different case, e.g.

Foo foo = new Foo(); // C#

Dim foo As New Foo() ' VB.NET

I find this is often the clearest way to write code, especially for small methods. This coding style obviously works fine in C#, being case sensitive, and because of the syntax highlighting provided by Visual Studio, it is very easy to see that the class name and the variable name are different.

However, to my surprise, this also worked fine nearly 100% of the time* in VB.NET. The only issue was that the variable name then appeared to take on a multiple identity. Namely it could be used to call both instance methods and Shared (static) methods of the Foo class. This didn’t really cause any problems though, it just meant that Intellisense would provide a list containing both static and instance methods after you hit the ‘.’ after the variable name.

I found, again to my surprise, that this didn’t actually lead to any confusion in my project, and it’s been very successful so far! However I was the only person working on this particular project.

Here is a slightly longer example:

Dim collection as Collection = New Collection()
For Each bar As Bar in Bar.All()
    collection.SomeInstanceMethod(bar)
Next
collection.SomeSharedMethod()

* The only issue I found with this was that sometimes the ‘Rename’ refactoring tool got confused, i.e. when renaming a class it would rename the variables with the same name as the class as well, in their declaration lines (Dim foo As...), but not the other references to that variable, causing compiler issues (duh). These were always easy to correct though.

Another small annoyance is that the VB.NET syntax highlighter doesn’t highlight class names any differently than variable names, making it not quite as nice as when using it in C#. I still found the code very readable though.

Has anyone else tried allowing this in a team environment? Are there any other potential issues with this naming convention in VB.NET?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:56:27+00:00Added an answer on May 12, 2026 at 10:56 am

    I’m going to differ with the rest of the answers here… I don’t think there is any problem with doing this. I do it regularly, and have absolutely 0 problems resulting from it.

    If you use lowercase for the variable name you can easily differentiate the variable from the type, and the compiler will not confuse the two identifiers.

    If you delete the variable declaration, the compiler will think other references to this variable now refer to the type, but it’s not really a problem because those will be tagged as errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a recent project I have been working on in C#/ASP.NET I have some
I'm using .NET 2.0, and a recent code change has invalidated my previous Assert.AreEqual
I'm using com.sun.net.httpserver.HttpServer in my project. However, it seems that the server leaks connections
With the recent announcement of .NET 4.0 and Visual Studio 2010, it is becoming
A recent question about string literals in .NET caught my eye. I know that
A recent question came up about using String.Format(). Part of my answer included a
This recent question about sorting randomly using C# got me thinking about the way
As a follow-up to my recent question about .NET Compact Framework debugging, I am
Why does the recent ASP.NET security vurnerability specify an html error page to redirect
A recent blunder was made where the Bug Tracker .NET software was removed from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.