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 634335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:17:04+00:00 2026-05-13T20:17:04+00:00

Some comments on Stack Overflow question Why doesn’t the C# compiler stop properties from

  • 0

Some comments on Stack Overflow question Why doesn’t the C# compiler stop properties from referring to themselves? regarding warnings got me thinking about old issues that always goofed me up when I was writing more VB.NET code.

One of them was the fact that the compiler didn’t warn if you declared a Function but never did an explicit Return statement or assign to the Function name. Running Visual Studio 2008, I just made a small experimental project, and it seems as though the behavior has never been fixed. I created a Visual Basic Console application, with the following code:

Module MainModule

    Sub Main()

        Dim test As Boolean = TestWarning()

    End Sub

    Function TestWarning() As Boolean

        Console.WriteLine("There is no Return Statement")

    End Function

End Module

I also went into the Project Settings and turned On Option Strict and Option Explicit. I also set the Warning Configurations so that "Function/Operator with no return value" was set to Error.

I compiled the project and got no warning, and no error on the TestWarning() Function. This seems like a great place to put a warning, because it will default to False, and you may have simply forgotten to do a return. C# will error without a return statement. I thought that VB.NET did the same thing with the "Function/Operator with no return value" configuration. Is this a bug, or is there something I’m missing?

Further Experimentation

Function TestWarning() As Boolean

    If DateTime.Now.DayOfWeek = DayOfWeek.Monday Then
        Return False
    Else
        Console.WriteLine("There is no Return Statement")
    End If

End Function

If I have an explicit Return in an If, and nothing in the Else, there is also no warning or error. It will simply take the default, even though you likely intended (via programming style) to have an explicit return. In this case, I explicitly returned False (which is the default for Boolean), so it’s likely a hidden bug that I should have returned True in the Else.

  • 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-13T20:17:05+00:00Added an answer on May 13, 2026 at 8:17 pm

    The warning will only let you know when a function is going to return Nothing by default.

    You would get a warning if return value was of a reference type.

    But your function has a return value of a value type, and those cannot be Nothing. Therefore, no warning.

    This is because function name inside this very function acts as a result variable. You can return a value by assigning it to the function name instead of using Return. And all variables are initialized with default values, including the function-name variable. This is not the case in C, hence the different meaning of the warning.

    Compare this to using variables before initializing them:

    Dim x As Integer
    CallFunction(x)  'No warning, x is implicitly and properly initialized to 0.
    
    Dim y as Object
    CallFunction(y)  'A warning: variable used before a value is assigned to it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I agree that implementing a WeakList<T> is possible, but I… May 14, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer I was running into this problem as well. I was… May 14, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer Multiply by 100 and parse the result as a string… May 14, 2026 at 8:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.