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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:40:04+00:00 2026-05-19T16:40:04+00:00

When using a string builder, I get expected results from the append and append

  • 0

When using a string builder, I get expected results from the append and append line functions when using an enum is the input, but when the enum is boxed the append line and append function give differing results.

Can anyone tell me what may be behind this?

Code output:

Append Enum: 1
Append Enum To String: One
Append Line Enum: 1
Append Line Enum To String: One
Append Object: One
Append Object To String: One
Append Line Object: 1
Append Line Object To String: One

Code:

Public Enum eTest
    One = 1
    Two = 2
End Enum

Sub Main()
    Dim sb As New System.Text.StringBuilder()
    Dim x = eTest.One
    sb.Append("Append Enum: ").Append(x).AppendLine()
    sb.Append("Append Enum To String: ").Append(x.ToString()).AppendLine()
    sb.Append("Append Line Enum: ").AppendLine(x)
    sb.Append("Append Line Enum To String: ").AppendLine(x.ToString())

    Dim o As Object = x
    sb.Append("Append Object: ").Append(o).AppendLine()
    sb.Append("Append Object To String: ").Append(o.ToString()).AppendLine()
    sb.Append("Append Line Object: ").AppendLine(o)
    sb.Append("Append Line Object To String: ").AppendLine(o.ToString())

    Console.WriteLine(sb.ToString())


    '===============================
    Console.ReadKey()
End Sub
  • 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-19T16:40:05+00:00Added an answer on May 19, 2026 at 4:40 pm

    This line

    sb.Append("Append Object: ").Append(o).AppendLine()
    

    causes o.ToString() to be appended to the instance of StringBuilder and that is the difference. Of course, that call just passes through to the boxed instance of your enum and this is why you see One for this invocation.

    This is because you are invoking the overload StringBuilder.Append(object) which will just invoke o.ToString() on the passed in instance of object. This is explicitly in the documentation:

    The Append method calls the Object.ToString method to get the string representation of value. If value is null, no changes are made to the StringBuilder object.

    On the other hand, when you call

    sb.Append("Append Enum: ").Append(x).AppendLine()
    

    where x is an instance of an enum, x will be implicitly converted to an instance of int which will call the overload StringBuilder.Append(int).

    Note that this is specific to VB.NET. C# will not implicitly convert x to an int when choosing which overload of StringBuilder.Append to invoke; it will invoke StringBuilder.Append(object).

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

Sidebar

Related Questions

I was using this code to get event from calendar. But I got error
Friends i'm using string builder for generating Passenger List in which i have used
I am using string template to render some content, but the content may be
I want to get user input using a pop-up dialog box. I am able
So from what I understand of a string vs StringBuilder is that string builder
I am using this alert dialog: public void displayAlert() { new AlertDialog.Builder(getActivity()).setMessage(R.string.invitenotice) .setTitle(Invite Notice)
I'm provided a library with a builder function using default/named params. Something like def
I try to replace some string in StringBuilder using the replace method, but unfortunately
I'm using Borland C++ Builder 6 to try to do some simple string concatenation.
From the MSDN Article I read I should be using the StringBuilder rather than

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.