gpt4 book ai didi

c# - Access 数据库的 3 位十六进制生成器

转载 作者:太空宇宙 更新时间:2023-11-03 22:48:54 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何创建一个始终在 C# 中输出 3 位数字并将其发送到我的访问数据库的十六进制生成器。这是我在此处找到示例并稍作更改的代码,但生成器有时只给我 2 位数字。我做错了什么?

谢谢,

        var r = new Random();
int A = r.Next(100, 500);
string hexValue1 = A.ToString("X");
MessageBox.Show(hexValue1);

最佳答案

如中所述

The Hexadecimal ("X") Format Specifier

The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.

所以你可以简单地使用

string hexValue1 = A.ToString("X3");

总是给你三位数(前提是 A <= 0xFFF)..

关于c# - Access 数据库的 3 位十六进制生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48530454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com