本文介绍了如何比较Long与UInt64(或从Long转换为UInt64)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的, 我使用以下代码检索某个文件的大小和磁盘上的可用(空闲)空间。问题是,我得到的大小为 文件返回为Long,可用磁盘空间大小为UInt64。 显然,没有转换功能一个很长的UInt64或者 比较两个(我不希望将UInt64转换成一个长的 ,但它应该反过来了,对吧?)。 短篇小说:如何比较一个长期和一个UInt64? 长话,请阅读下面的代码看到 最后评论声明中描述的问题 ''------ snip - snip ------- Dim objDiskClass As System.Management.ManagementClass Dim objDisks As System.Management.ManagementObjectCollection Dim objDisk As System.Management.ManagementObject Dim lFileSize As Long Dim uiDiskSpace As System.UInt64 Dim objFileInfo = New FileInfo(" MyFile.txt") lFileSize = objFileInfo.Length objDiskClass = New System.Management.ManagementClass(" Win32_LogicalDi sk") objDisks = objDiskClass.GetInstances() For objDisk中的每个objDisk 如果CStr(objDisk(" Name"))=D:然后 uiDiskSpace = CType(objDisk(" FreeSpace"),System.UInt64) 退出 结束如果 下一个objDisk ''现在我在lFileSize中获得了文件大小的长度 ''和uiDiskSpace中的可用磁盘空间为UInt64 /> ''???我怎么能比较两个??? ''------ snip - snip ------- 谢谢你的帮助还有一些很棒的假期! 沃尔夫冈 解决方案 问候 - OHM #OneHandedMan {at} BTInternet {dot} com 除非你期望查询超过90亿GB的磁盘 的可用空间,只需将uiDiskSpace声明为Long。 " Wolfgang Kaml" < [email protected]>在消息中写道 新闻:大江************** @ TK2MSFTNGP10.phx.gbl ... 并将UInt64分配给Long won'也没办法,因为那时候 我得到了一个 类型''System.UInt64''的值不能转换成''Long''。 请告诉我你想要如何完成你提出的解决方案。 谢谢, Wolfgang " Stephen Martin" < SM ***** @ removethis.emsoft.andthis.ca>在消息中写道 news:eh ************** @ TK2MSFTNGP12.phx.gbl ... 磁盘上的 作为一个Long返回的文件和可用磁盘空间的大小为UInt64。显然,有没有功能可以将Long转换为UInt64或者比较两者(我不希望将UInt64转换为Long 必然,但它应该反过来,对吧?) 。短篇小说:如何比较一个很长的UInt64? 很长一段时间,请阅读下面的代码,看看最后一个中描述的问题评论声明''------ snip - snip ------- Dim objDiskClass As System.Management.ManagementClass Dim objDisks As System.Management.ManagementObjectCollection Dim objDisk As System.Management.ManagementObject Dim lFileSize As Long Dim uiDiskSpace As System.UInt64 Dim objFileInfo = New FileInfo(" MyFile.txt") lFileSize = objFileInfo.Length objDiskClass = New System.Management.Ma nagementClass(" Win32_LogicalDi sk")objDisks = objDiskClass.GetInstances() 对于objDisk中的每个objDisk 如果CStr(objDisk(" Name"))=" D:"然后 uiDiskSpace = CType(objDisk(" FreeSpace"),System.UInt64)退出结束如果下一个objDisk ''现在我在lFileSize中获得了文件大小的长度''和uiDiskSpace中的可用磁盘空间为UInt64 ''???我如何比较两个??? ''------剪断 - 剪切------- 感谢您的帮助,并且有一些很棒的假期呢! Wolfgang Dear all,I am using the following code to retrieve the size of a certain file and theavailable (free) space on the disk. The problem is, that I get the size ofthe file returned as a Long and the size of free disk space as UInt64.Apparently, there are no function to convert a Long to a UInt64 or tocompare the two (I''m not expecting to convert the UInt64 to a Longnecessarily, but it should work the other way round, right?).Short story: How to compare a Long with a UInt64?Long story, please read the code below to see the problem described in thevery last comment statement''------ snip - snip -------Dim objDiskClass As System.Management.ManagementClassDim objDisks As System.Management.ManagementObjectCollectionDim objDisk As System.Management.ManagementObjectDim lFileSize As LongDim uiDiskSpace As System.UInt64Dim objFileInfo = New FileInfo("MyFile.txt")lFileSize = objFileInfo.LengthobjDiskClass = New System.Management.ManagementClass("Win32_LogicalDi sk")objDisks = objDiskClass.GetInstances()For Each objDisk In objDisksIf CStr(objDisk("Name")) = "D:" ThenuiDiskSpace = CType(objDisk("FreeSpace"), System.UInt64)Exit ForEnd IfNext objDisk''now I got the File Size as Long in lFileSize''and the Free Disk Space as UInt64 in uiDiskSpace''??? How can I compare the two ???''------ snip - snip -------Thank you for all of your help and have some great holidays too!Wolfgang 解决方案Regards - OHM# OneHandedMan{at}BTInternet{dot}comAnd assigning the UInt64 to a Long won''t work either, because at that pointI get a"Value of type ''System.UInt64'' cannot be converted to ''Long''.PLEASE show me of how you want to accomplish your proposed solution.Thanks,Wolfgang"Stephen Martin" <sm*****@removethis.emsoft.andthis.ca> wrote in messagenews:eh**************@TK2MSFTNGP12.phx.gbl... theof the file returned as a Long and the size of free disk space as UInt64. Apparently, there are no function to convert a Long to a UInt64 or to compare the two (I''m not expecting to convert the UInt64 to a Long necessarily, but it should work the other way round, right?). Short story: How to compare a Long with a UInt64? Long story, please read the code below to see the problem described inthe very last comment statement ''------ snip - snip ------- Dim objDiskClass As System.Management.ManagementClass Dim objDisks As System.Management.ManagementObjectCollection Dim objDisk As System.Management.ManagementObject Dim lFileSize As Long Dim uiDiskSpace As System.UInt64 Dim objFileInfo = New FileInfo("MyFile.txt") lFileSize = objFileInfo.Length objDiskClass = NewSystem.Management.ManagementClass("Win32_LogicalDi sk") objDisks = objDiskClass.GetInstances() For Each objDisk In objDisks If CStr(objDisk("Name")) = "D:" Then uiDiskSpace = CType(objDisk("FreeSpace"), System.UInt64) Exit For End If Next objDisk ''now I got the File Size as Long in lFileSize ''and the Free Disk Space as UInt64 in uiDiskSpace ''??? How can I compare the two ??? ''------ snip - snip ------- Thank you for all of your help and have some great holidays too! Wolfgang 这篇关于如何比较Long与UInt64(或从Long转换为UInt64)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-14 00:09