csharp-杂项

全屏

this.WindowStyle = System.Windows.WindowStyle.None;
this.WindowState = System.Windows.WindowState.Maximized;

退出全屏

//按Esc键退出全屏
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)//Esc键
{
this.WindowState = System.Windows.WindowState.Normal;
this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
}
}

int to bytes array

var byArr = BitConverter.GetBytes(Int);

// If the system architecture is little-endian (that is, little end first),
// reverse the byte array.
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);

.net core gb2312 不支持

System.Text.EncodingProvider provider = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(provider);

判断系统

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Windows 相关逻辑
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Linux 相关逻辑
}