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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:36:01+00:00 2026-06-09T04:36:01+00:00

I just wrote a small Unit Test in which I used a StringBuilder() .

  • 0

I just wrote a small Unit Test in which I used a StringBuilder().

var stringBuilder = new StringBuilder();
stringBuilder.Append("Foo");

Assert.AreEqual(stringBuilder, "Foo");

This Test will fail.

Expected: <Foo>
But was:  "Foo"

But if I change the Assert to

Assert.AreEqual(stringBuilder.ToString(), "Foo");

the test will pass.

So, what is the difference between the implicit call and the explicit call of the ToString() method? Or/And what are these Brackets (<>) standing for?

  • 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-09T04:36:03+00:00Added an answer on June 9, 2026 at 4:36 am

    In your first example, you are testing if your StringBuilder instance is equal to the string, which will fail.

    In your second one, you are testing if the result of the call to ToString() (which is a string) is equal to the other string.


    The bracktes (<>) are NUnits way to indicate that it got an non-string object, but to display the message, NUnit calls ToString() on that object.

    Expected: <Foo> But was: "Foo"
    

    So <Foo> is an object that returns Foo on a call to ToString(), whereas "Foo" is just a String Foo.

    MSTest would show you a different message, which would be more clear:

    Expected:<Foo (System.Text.StringBuilder)>. Actual:<Foo (System.String)>.   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this small code just to see how an iterator actually gets invalidated
I wrote a small queue class in C++, on Windows. Just to test, I'm
I am new at C# and mono. I just wrote a small GtkSharp program
I just wrote a small program which takes the input from user and shows
I just started playing with Clojure, and I wrote a small script to help
I just wrote some new utility methods within a non-page class for an existing
I just wrote this into my WebForms .aspx: <span id=GenerateChartButton runat=server></span> I went to
I just wrote some code to test the behavior of std::equal, and came away
I am just starting out with writing jQuery plugins. I wrote three small plugins
I have here a small question. I wrote a small multi threaded app which

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.