What does beforefieldinit flag do?

See my article on this very issue. Basically, beforefieldinit means “the type can be initialized at any point before any static fields are referenced.” In theory that means it can be very lazily initialized – if you call a static method which doesn’t touch any fields, the JIT doesn’t need to initialize the type. In … Read more

What is the purpose of hidebysig in a MSIL method?

From ECMA 335, section 8.10.4 of partition 1: The CTS provides independent control over both the names that are visible from a base type (hiding) and the sharing of layout slots in the derived class (overriding). Hiding is controlled by marking a member in the derived class as either hide by name or hide by … Read more

Weird performance increase in simple benchmark

There is a very simple way to always get the “fast” version of your program. Project > Properties > Build tab, untick the “Prefer 32-bit” option, ensure that the Platform target selection is AnyCPU. You really don’t prefer 32-bit, unfortunately is always turned on by default for C# projects. Historically, the Visual Studio toolset worked … Read more

Why does this (null || !TryParse) conditional result in “use of unassigned local variable”?

I am pretty sure this is a compiler bug. Nice find! Edit: it is not a bug, as Quartermeister demonstrates; dynamic might implement a weird true operator which might cause y to never be initialized. Here’s a minimal repro: class Program { static bool M(out int x) { x = 123; return true; } static … Read more

Why does the C# compiler translate this != comparison as if it were a > comparison?

Short answer: There is no “compare-not-equal” instruction in IL, so the C# != operator has no exact correspondence and cannot be translated literally. There is however a “compare-equal” instruction (ceq, a direct correspondence to the == operator), so in the general case, x != y gets translated like its slightly longer equivalent (x == y) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)