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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:57:09+00:00 2026-06-02T23:57:09+00:00

Anyone have any ideas why this doesn’t work (C# or VB.NET or other .NET

  • 0

Anyone have any ideas why this doesn’t work (C# or VB.NET or other .NET language doesn’t matter). This is a very simplified example of my problem (sorry for VB.NET):

    Private itsCustomTextFormatter As String
    Public Property CustomTextFormatter As String
        Get
            If itsCustomTextFormatter Is Nothing Then CustomTextFormatter = Nothing  'thinking this should go into the setter - strangely it does not'
            Return itsCustomTextFormatter
        End Get
        Set(ByVal value As String)
            If value Is Nothing Then
                value = "Something"
            End If
            itsCustomTextFormatter = value
        End Set
    End Property

If you do:

Dim myObj as new MyClass
Console.WriteLine(myObj.CustomTextFormatter)

You will be surprised at the result. It will print “Nothing”. Anyone have any idea why it doesn’t print “Something”

Here’s a Unit Test per suggestion:

Imports NUnit.Framework

<TestFixture()> _
Public Class Test
   Private itsCustomTextFormatter As String
    Public Property CustomTextFormatter As String
        Get
            If itsCustomTextFormatter Is Nothing Then CustomTextFormatter = Nothing 'thinking this should go into the setter - strangely it does not' 
            Return itsCustomTextFormatter
        End Get
        Set(ByVal value As String)
            If value Is Nothing Then
                value = "Something"
            End If
            itsCustomTextFormatter = value
        End Set
    End Property

    <Test()>
    Public Sub Test2()
        Assert.AreEqual("Something", CustomTextFormatter)
    End Sub
End Class

This returns:

Test2 : Failed  
  Expected: "Something"
  But was:  null

at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.AreEqual(Object expected, Object actual)
  • 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-06-02T23:57:10+00:00Added an answer on June 2, 2026 at 11:57 pm

    Your comment:

    'thinking this should go into the setter - strangely it does not'    
    

    calls out what your error is. In Visual Basic there are two ways to return something from a function:

    Function GetSomeValue() As String
        Return "Hello"
    End Function
    

    or

    Function GetSomeValue() As String
        GetSomeValue = "Hello"
    End Function
    

    Mixing these two styles is perfectly legal, but confusing and a bad practice:

    Function GetSomeValue() As String
        GetSomeValue = "Hello" ' I should return Hello... '
        Return "GoodBye"       ' ...or perhaps not. '
    End Function
    

    As you can see, you are mixing the two styles in the getter. Setting that variable does not call the setter; it informs the runtime that when the getter returns, this is the value that it should return. You then override that value with your Return statement.

    If it hurts when you do that then don’t do that.

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

Sidebar

Related Questions

Anyone have any ideas to clean this up? public string FullName { get {
I don't have any idea how to use this class in .net. Anyone wants
Anyone have any ideas on how to hide the .NET PasswordStrength control until after
Does anyone have any idea what this jQuery selector will do? object.find('td:eq(1) div div');
Does anyone have any idea what is wrong with this create statement for mysql?
Anyone have any ideas what I can do? Please reserve commenting about using 1.1
Anyone have any ideas on a good way to model the following scenario in
Does anyone have any ideas on how to read the MSDTC configuration on the
Does anyone have any ideas or know of any plugins to allow pages to
Anyone have any idea how to get the value of Language for Non-Unicode Programs

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.