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

The Archive Base Latest Questions

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

So C# now allows you to use default(Foo) to get a recognized not filled

  • 0

So C# now allows you to use default(Foo) to get a recognized ‘not filled in yet’/empty instance of a class — I’m not sure if it is exactly the same as new Foo() or not. Many library classes also implement a Foo.Empty property, which returns a similar instance. And of course any reference type can point to null. So really, what’s the difference? When is one right or wrong? What’s more consistent, or performs better? What tests should I use when checking if an object is conceptually ‘not ready for prime time’? Not everybody has Foo.IsNullOrEmpty().

  • 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. 2026-05-10T16:49:20+00:00Added an answer on May 10, 2026 at 4:49 pm

    default(Foo) will return null when Foo is a class type, zero where Foo is a value type (such as int), and an instance of Foo with all fields initialized to their respective default() values where Foo is a struct. It was added to the language so that generics could support both value and reference types – more info at MSDN

    Use default(Foo) when you’re testing a T in the context of SomeClass<T> or MyMethod<T> and you don’t know whether T will be value type, a class type or a struct.

    Otherwise, null should mean ‘unknown’, and empty should mean ‘I know this is empty’. Use the Foo.Empty pattern if you genuinely need an empty – but non-null – instance of your class; e.g. String.Empty as an alternative to '' if you need to initialize some variable to the empty string.

    Use null if you know you’re working with reference types (classes), there’s no generics involved, and you’re explicitly testing for uninitialized references.

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • 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 wonder if it wouldn't be better to include json… May 11, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer I think You should not use unix sockets. If Your… May 11, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer If none of the TargetDir or other macros point to… May 11, 2026 at 4:38 pm

Related Questions

I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I am trying to join a number of binary files that were split during
Are there any 'good' resources for porting a VB.NET winforms application to C#? I'm
At my current job, we're looking to implement our own odbc driver to allow

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.