Ordering of static fields in C# matters

via Ordering of static fields in C# matters

The ordering of static fields does matter.
But per your examples, here is the pattern I always use:

public class Person
    private static EmptyPerson _emptyPerson;
    public static Person Empty => _emptyPerson ?? ( _emptyPerson = new EmptyPerson() );

The allows the Empty value to be initialized once and read-only, yet still used many times.
It also hides away the requirements of the initialization (the value pulled from a database for example) from the public getter. We could even put the value into a Lazy<Person>().

And in C# 8.0 we now have the compound assignment!

public class Person
    private static EmptyPerson _emptyPerson;
    public static Person Empty => _emptyPerson ??= new EmptyPerson();


Posted in C#

Samsung NVMe 3.1 Driver

Download Here: Samsung NVMe 3.1 Driver
Password: “Samsung“.

I created this because sometimes the windows executable from Samsung won’t install if a temp folder is not set correctly.

This archive is the 3 files from the official Samsung NVMe 3.1 driver download page with no modifications, just zipped up.

Remember: Always create a Restore Point before you install, and keep your antivirus ENABLED.. just to be on the safe side.

Here are my results before installing this driver.
nvme standard 1GB

And the results after installing this driver.
nvme samsung 1GB

Conclusion: only slightly better than Microsoft’s NVMe driver on this computer. Both results are within the margin of error for a Windows Pro workstation computer.

Sending a text message from SQL Server

You must have SQL Server database mail enabled for this stored procedure to work.

CREATE proc [dbo].[SendTextMessage](
@number nvarchar(255)
,@message nvarchar(255)
,@subject nvarchar(255) = null
,@provider nvarchar(20) = 'Verizon'
set nocount on;

set @number = ltrim(rtrim(@number));
if @number is null or len(@number)<7 begin;
set @message = '@number is too short';
throw 51000, @message, 1;

set @message = ltrim(rtrim(@message));
if @message is null or len(@message)<2 begin;
set @message = '@message is too short';
throw 51000, @message, 1;

set @subject = ltrim(rtrim(@subject));
if @subject is null set @subject = @@SERVERNAME + N' Notification';

declare @to nvarchar(255) = @number + N'@'+
case @provider
when 'Verizon' then N'vtext.com'
when 'VZ' then N'vtext.com'
when 'ATT' then N'txt.att.net'
when 'SPRINT' then N'messaging.sprintpcs.com'
when 'TMOBILE'  then N'tmomail.net'
if nullif(@provider,N'@') is null begin;
throw 51000, 'Unknown provider. Message not sent.', 1;

begin try;
declare @mailitem_id INT;
exec msdb.dbo.sp_send_dbmail @recipients = @to, @subject = @subject, @body = @message, @mailitem_id=@mailitem_id output;
end try
begin catch;
throw 51000, 'Unknown error calling msdb.dbo.sp_send_dbmail.', 1;
end catch;

(a minor) Open Letter to NVidia, from one Developer to another..

Hey, just a quick easy request from a simple Developer: Please make your video card driver installers’ default to use the Temp environment path variables I have configured on my computers.

Please? Other than installing the telemetry without asking, you’re doing great on keeping our systems updated!

My C: (system) SSD disk is reserved for the Windows 10 Operating System.. not temp files.