c# - 无法在 C# 中声明任何有符号整数类型
问题描述
我正在使用 Visual Studio 2019 中的 ASP.NET 应用程序。我遇到了一个我以前从未遇到过的 C# 问题。我似乎无法声明 UInt64 以外的任何整数类型。
尝试声明 Int64 或 long 会给我错误,因为它表示我正在尝试将 UInt64(或 ulong)转换为其中一种类型。
具体错误如下(显示的 Azure 租户 ID 是虚拟值,不要惊慌):
线
Int64 tenantInt = 11132432026456784806;
给出以下错误
Error CS0266 Cannot implicitly convert type 'ulong' to 'long'. An explicit conversion exists (are you missing a cast?)
然后是下面的代码行
long TenantID = -11132432026456784806;
给出以下错误
Error CS0023 Operator '-' cannot be applied to operand of type 'ulong'
这是相同错误的图像: HERE
我以前在 C# 中工作时从未遇到过这种情况。通常这些声明工作正常。Visual Studio 有问题吗?它不断将数字读取为 UInt64,并尝试使用 (Int64) 或 (long) 进行转换遇到另一个错误,即 UInt64(或 ulong)无法转换为这些类型。
解决方案
您必须使用“ulong”,因为支持 18.446.744.073.709.551.615。
推荐阅读
- scala - 如何将几列的值合并到 Spark Dataframe 中的地图中
- google-sheets - 有没有办法在 Google 表格上部署机器学习模型?
- python - 尝试连接到 dask 仪表板时出现“404 Not found”
- c++ - 带有“无限”参数的 c++ 模板
- electron - 在 Cypress 中设置 Electron 的语言
- javascript - 如何在各个页面中具有相同 ID 的多个页面上使用 JavaScript 隐藏/显示链接(元素)?
- php - PHP:file_get_contents():SSL 操作失败,代码为 1
- java - 未使用改造从 IGDB Api 接收所有数据
- sql - SSRS - 具有不同价值的多个数据
- javascript - 停止提交按钮不发布并返回同一页面