其中一个GUID的一部分,是最值得保留? [英] Which part of a GUID is most worth keeping?

查看:172
本文介绍了其中一个GUID的一部分,是最值得保留?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一个唯一的ID,并正在考虑 Guid.NewGuid 来做到这一点,它生成表单的东西:

I need to generate a unique ID and was considering Guid.NewGuid to do this, which generates something of the form:

0fe66778-c4a8-4f93-9bda-366224df6f11



< 。p>这是字符串类型的数据库列,它最终将居住在一点点长,所以我打算截断它

This is a little long for the string-type database column that it will end up residing in, so I was planning on truncating it.

的问题是:一个GUID的一端较独特的角度其余更佳?我应该砍掉的开始,结束,或从中间移除部分? ?还是只是没有关系。

The question is: Is one end of a GUID more preferable than the rest in terms of uniqueness? Should I be lopping off the start, the end, or removing parts from the middle? Or does it just not matter?

推荐答案

您可以通过使用base64字符串,而不是节省空间:

You can save space by using a base64 string instead:

var g = Guid.NewGuid();
var s = Convert.ToBase64String(g.ToByteArray());

Console.WriteLine(g);
Console.WriteLine(s);

这将(如果你不使用连字符8)为您节省12个字符。

This will save you 12 characters (8 if you weren't using the hyphens).

这篇关于其中一个GUID的一部分,是最值得保留?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆