unsafe C#

        unsafe void ShowBytes(byte* start, int len)
        {
            for (int i = 0; i < len; i++)
            {
                Console.Write("{0}", start[i].ToString("X2"));
            }
            Console.WriteLine();
        }
        unsafe void ShowShort(short x)
        {
            ShowBytes((byte*)&x, sizeof(short));
        }
        unsafe void ShowShort(int x)
        {
            ShowBytes((byte*)&x, sizeof(int));
        }

        unsafe void ShowShort(uint x)
        {
            ShowBytes((byte*)&x, sizeof(uint));
        }
        unsafe void ShowShort(float x)
        {
            ShowBytes((byte*)&x, sizeof(float));
        }
        unsafe void ShowShort(char x)
        {
            ShowBytes((byte*)&x, sizeof(char));
        }
        unsafe void show<T>(T x)
        {
            Console.Write(x.ToString());
        }

REF: c n blog s . com / Hope G i / p / 6901880.html

To set this compiler option in the Visual Studio development environment

  1. Open the project's Properties page.
  2. Click the Build property page.
  3. Select the Allow Unsafe Code check box.
If your application is a web service, Directory.CurrentDirectory doesn't work.
Use System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), "yourFileName.txt")) instead.
When you provide a path, it can be absolute/rooted, or relative. If you provide a relative path, it will be resolved by taking the working directory of the running process.
Example:
string text = File.ReadAllText("Some\\Path.txt"); // relative path
The above code has the same effect as the following:
string text = File.ReadAllText(
    Path.Combine(Environment.CurrentDirectory, "Some\\Path.txt"));
You could use Directory.GetCurrentDirectory:

var path = Path.Combine(Directory.GetCurrentDirectory(), "\\fileName.txt");
Which will look for the file fileName.txt in the current directory of the application.
end;
Guid:
https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=netframework-4.8#System_Guid_ToString
> Guid.NewGuid()。ToString()=> 36个字符(连字符)
output:12345678-1234-1234-1234-123456789abc
> Guid.NewGuid()。ToString(“D”)=> 36个字符(连字符,与ToString()相同)
output:12345678-1234-1234-1234-123456789abc
> Guid.NewGuid()。ToString(“N”)=> 32个字符(仅数字)
output:12345678123412341234123456789abc
> Guid.NewGuid()。ToString(“B”)=> 38个字符(大括号)
output:{12345678-1234-1234-1234-123456789abc}
> Guid.NewGuid()。ToString(“P”)=> 38个字符(括号)
output:(12345678-1234-1234-1234-123456789abc)
> Guid.NewGuid()。ToString(“X”)=> 68个字符(十六进制)
output:{0x12345678,0x1234,0x1234,{0x12,0x34,0x12,0x34,0x56,0x78,0x9a,0xbc}}
N 32 digits: 00000000000000000000000000000000
D 32 digits separated by hyphens:
00000000-0000-0000-0000-000000000000
B 32 digits separated by hyphens, enclosed in braces:
{00000000-0000-0000-0000-000000000000}
P 32 digits separated by hyphens, enclosed in parentheses:
(00000000-0000-0000-0000-000000000000)
X Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:
{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE