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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:33:21+00:00 2026-05-11T13:33:21+00:00

When assigning a default default-value to a field (here false to a bool), FxCop

  • 0

When assigning a default default-value to a field (here false to a bool), FxCop says:

Resolution   : "'Bar.Bar()' initializes field 'Bar.foo'                 of type 'bool' to false. Remove this initialization                 because it will be done automatically by the runtime." 

Now, I know that code as int a = 0 or bool ok = false is introducing some redundancy, but to me it seems a very, very good code-practice, one that my teachers insisted on righteously in my opinion.

Not only is the performance penalty very little, more importantly: relying on the default is relying on the knowledge of each programmer ever to use a piece of code, on every datatype that comes with a default. (DateTime?)

Seriously, I think this is very strange: the very program that should protect you from making all too obvious mistakes, is suggesting here to make one, only for some increased performance? (we’re talking about initialization code here, only executed once! Programmers who care that much, can of course omit the initialization (and should probably use C or assembler 🙂 ).

Is FxCop making an obvious mistake here, or is there more to it?

Two updates :

  1. This is not just my opinion, but what I have been taught at university (Belgium). Not that I like to use an argumentum ad verecundiam, but just to show that it isn’t just my opinion. And concerning that:

  2. My apologies, I just found this one:

    Should I always/ever/never initialize object fields to default values?

  • 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-11T13:33:21+00:00Added an answer on May 11, 2026 at 1:33 pm

    There can be significant performance benefits from this, in some cases. For details, see this CodeProject article.

    The main issue is that it is unnecessary in C#. In C++, things are different, so many professors teach that you should always initialize. The way the objects are initialized has changed in .NET.

    In .NET, objects are always initialized when constructed. If you add an initializer, it’s possible (typical) that you cause a double initialization of your variables. This happens whether you initialize them in the constructor or inline.

    In addition, since initialization is unnecessary in .NET (it always happens, even if you don’t explicitly say to initialize to the default), adding an initializer suggests, from a readability standpoint, that you are trying to add code that has a function. Every piece of code should have a purpose, or be removed if unnecessary. The ‘extra’ code, even if it was harmless, suggests that it is there for a reason, which reduces maintainability.

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

Sidebar

Related Questions

I am having a problem assigning a default value to my Spring Form input
Question What is a good way of assigning a default value to an optional
When assigning a default value to a uint parameter in a C# method argument,
In a lot of apps I write, I find myself assigning a default value
When assigning a type casted array to codeigniter's session, I get this error: A
In Perl, if I want to default a value that might exist, for example
What is the default value of unsigned int in c#? For ex: int, its
All struct s in C# by default are treated as [StructLayout(LayoutKind.Sequential)] -marked value types.
From Python docs: sys.excepthook(type, value, traceback) This function prints out a given traceback and
In my form, I want to set the selected (default) value for a select

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.