在 VB.NET 中生成本地唯一标识符的首选方法是什么? [英] What is the preferred method for generating locally unique identifiers in VB.NET?

查看:37
本文介绍了在 VB.NET 中生成本地唯一标识符的首选方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为本地创建的记录类生成唯一标识符的方法,然后以各种格式(XML、SQL 等)保存

I'm looking for a method of generating unique identifiers for a record class being created locally and then persisted in various formats (XML, SQL, etc.)

我见过有人使用 DateTime 和 GetHashCode,但这似乎有助于根据样本大小重复标识符.

I've seen people using DateTime and GetHashCode, but that seems to lend itself to duplicate identifiers depending upon the sample size.

GUID 有点矫枉过正,因为我不需要任何在全球范围内独特(大)的东西.我也知道使用 GUID 和 GetHashCode 来减小大小,但这里也会出现重复项.

GUID is a bit overkill, as I don't need anything that unique (large) at the global level. I'm also aware of using GUIDs and GetHashCode to get the size down a bit, but duplicates tend to crop up here as well.

谁能建议生成简单唯一标识符的最佳实践或方法?

Can anyone suggest a best practice or method for generating simple unique identifiers?

推荐答案

Guid 或递增计数器.

Guid or increasing counter.

Guid 可以从空气中"生成,但需要更多空间

Guid can be generated "from air" but takes more space

对于计数器,您需要将计数器存储在某处,并且如果您使用线程,则需要使其线程安全.但体积较小.

For counter you need to store the counter somewhere and you will need to make it thread safe if you use threads. But it is smaller in size.

这篇关于在 VB.NET 中生成本地唯一标识符的首选方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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