Here's another example:
using (var sftp = new SftpClient(host, username, password))
{
sftp.HostKeyReceived += (sender, e) => {
var knownFingerprint = "ssh-rsa 2048 5b:eb:4e:ef:ab:cd:25:2c:37:58:b6:2d:08:d5:56:12";
var providedFingerprint = String.Format(
"{0} {1} {2}",
e.HostKeyName,
e.KeyLength,
String.Join(":", e.FingerPrint.Select(b => b.ToString("x")))
);
e.CanTrust = knownFingerprint == providedFingerprint;
};
sftp.Connect(); // <- HostKeyReceived executes. If CanTrust was set to false, Connect() will throw an exception
// ...
}