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

  • Home
  • SEARCH
  • 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 6208267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:46:48+00:00 2026-05-24T05:46:48+00:00

I thought that enums in VB and C# where the same or at least

  • 0

I thought that enums in VB and C# where the same or at least very similar. Then today I stumbled across a bug in our VB code. The following VB code compiles and runs with no issues:

Enum Cars
    Subaru
    Volvo
End Enum

Enum Vegtables
    Carrots
    Beets
End Enum

Sub Main()
    Foo(Cars.Subaru)
    Foo(Vegtables.Carrots)
End Sub

Public Sub Foo(ByVal value As Cars)
End Sub

But the equivalent in C# correctly shows an error:

enum Cars
{
    Subaru,
    Volvo
}

enum Vegtables
{
    Carrots,
    Beets
}

class Program
{
    static void Main(string[] args)
    {
        Foo(Cars.Subaru);
        Foo(Vegtables.Carrots);//<-- C# detects a type mismatch here
    }

    public static void Foo(Cars carsValue)
    {}
}

Why does the VB version not catch the type mismatch? Are enum in VB and C# different?

  • 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-24T05:46:49+00:00Added an answer on May 24, 2026 at 5:46 am

    Why does the VB version not catch the type mismatch?

    You already got an answer to that from Bala R — try Option Strict On.

    Are enum in VB and C# different?

    It’s not the enums themselves that are different (your declarations in both C# and VB.NET are as equivalent to one another as they can be and will in all probability result in identical CIL “bytecode”). It’s rather that the compilers differ in the type safety they provide at compile-time / the implicit type coercion they allow.

    If type safety is very important to you, then enums probably aren’t the best option. Even C# allows you to (explicitly) cast a value of one enum type to a different enum type.

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

Sidebar

Related Questions

No related questions found

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.