I have a PDF downloaded from MS site, dotnet-csharp.pdf
, and it mentions 0-bit pattern. I did a quick search but got no results, can anyone explain this or have a link to a wiki page. I am assuming it is just using 0 / 1 in memory addresses but not sure.
In a struct, the implicit parameterless constructor initializes all fields, including primary constructor parameters to the 0-bit pattern
I really like C# docs for review and learning, not sure how this isn’t searchable as a term, rare this happens.
Thanks!
I’ve done internet searching only.
3
I don’t know in what document you’ve encountered this (next time, a link can help) but the relevant part of the C# language specification states the following:
All value types implicitly declare a public parameterless instance
constructor called the default constructor. The default constructor
returns a zero-initialized instance known as the default value for the
value type:
- For all simple_types, the default value is the value produced by a bit
pattern of all zeros:- For sbyte, byte, short, ushort, int, uint, long, and ulong, the default value is 0.
- For char, the default value is ‘x0000’.
- For float, the default value is 0.0f.
- For double, the default value is 0.0d.
- For decimal, the default value is 0m (that is, value zero with scale 0).
- For bool, the default value is false.
- For an enum_type E, the default value is 0, converted to the type E.
- For a struct_type, the default value is the value produced by setting all value type fields to their default value and all reference type fields to null.
- For a nullable_value_type the default value is an instance for which the HasValue property is false. The default value is also known as the null value of the nullable value type.
So basically, the 0 bit pattern is simply the default values for the types. I don’t know why the authors of the document you’ve read chose to use this phrasing (especially since .NET is a managed environment and direct memory storage is mostly an implementation detail [except when working on performance-critical code where you might benefit from direct memory access (using the unsafe keyword)])