简体   繁体   English

CInt和GetHashCode

[英]CInt and GetHashCode

I came across some weird VB codes, when I am about to convert some VB codes to C#: 当我要将一些VB代码转换为C#时,遇到了一些奇怪的VB代码:

totalLinks = table1.Rows(i).Item("qty").GetHashCode) *  CInt(table2.Rows(i).Item("numOfLinks").GetHashCode + 1)

(The business logic should be getting the total of links = qty * numOfLinks). (业务逻辑应该获取链接总数= qty * numOfLinks)。

table1 is a Datatable, and qty & numOfLinks are two columns from it. table1是一个数据表,而qty和numOfLinks是其中的两列。

Question1: Can we get a Integer by applying 'CInt' to a hashcode like above? 问题1:是否可以通过将“ CInt”应用于上面的哈希码来获得整数?

Question2: What does it mean by letting hashcode plus 1 and then get converted to integer like above? 问题2:让哈希码加1,然后像上面一样转换为整数,这是什么意思? (should be converted to integer first and then plus 1? or I actually misunderstood the codes?) (应该先转换为整数,然后再转换为1?还是我实际上误解了代码?)

I don't know how to convert it to C# before I understand exactly the meaning. 在我确切理解其含义之前,我不知道如何将其转换为C#。 Thanks! 谢谢!

Someone had no idea what they were doing with this code, but just got lucky that it worked. 有人不知道他们在用这段代码做什么,但是很幸运它能起作用。

GetHashCode happens to return the underlying value for Integer variables because there is really nothing to hash. GetHashCode碰巧返回Integer变量的基础值,因为实际上没有什么可哈希的。

Therefore, you can (should) simply ignore the GetHashCode code and convert the code as 因此,您可以(应该)简单地忽略GetHashCode代码并将其转换为

totalLinks = CInt(table1.Rows(i).Item("qty")) * (CInt(table2.Rows(i).Item("numOfLinks")) + 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM