.net开发还在使用guid吗?下面几种id生成器更加合适

 <ItemGroup>
    <PackageReference Include="IdGen" Version="3.0.5" />
    <PackageReference Include="Nanoid" Version="3.0.0" />
    <PackageReference Include="Snowflake.Core" Version="2.0.0" />
  </ItemGroup>
public async Task<string> DoworkIDs()
    {
        // IdGenerator idgen = new IdGenerator();
        // long getid = idgen.CreateId();

        string nanoidStr = await NanoidDotNet.Nanoid.GenerateAsync();

        long getId3 = new IdGen.IdGenerator(3).CreateId();
        long getId10 = new IdGen.IdGenerator(10).CreateId();

        Snowflake.Core.IdWorker snowflake = new Snowflake.Core.IdWorker(1,2,8);
        long snowflakeId = snowflake.NextId();
  
        return await Task.FromResult($"==getId3=={getId3},=====getId10={getId10},=====nanoidStr={nanoidStr}===snowflakeId=={snowflakeId}");
    }

 

posted @ 2024-04-26 11:39  天天向上518  阅读(31)  评论(0编辑  收藏  举报