如何比较Long与UInt64(或从Long转换为UInt64)? [英] how to compare a Long with a UInt64 (or convert fromLong to UInt64)?

查看:213
本文介绍了如何比较Long与UInt64(或从Long转换为UInt64)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我使用以下代码检索某个文件的大小和磁盘上的可用(空闲)空间。问题是,我得到的大小为

文件返回为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 -------

谢谢你的帮助还有一些很棒的假期!

沃尔夫冈

解决方案

未经测试。 。


Dim ui As UInt64 = Convert.ToUInt64(500)

Dim int64 = Convert.ToInt64(ui)
<问候 - OHM


Wolfgang Kaml写道:

亲爱的,

我正在使用以下代码检索某个文件的大小和磁盘上的可用(空闲)空间。问题是,我将文件的大小作为一个Long返回,并将可用磁盘空间的大小作为UInt64。显然,没有功能可以将Long
转换为UInt64或比较两者(我不希望将
UInt64转换为Long必须,但它应该反过来工作对吧?)。

短篇小说:如何将长龙与UInt64进行比较?

很长一段时间,请阅读下面的代码,看看所描述的问题
在最后一条评论语中
''------ snip - snip -------
Dim objDiskClass As System.Management.ManagementClass
Dim objDisks作为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()

对于objDisk中的每个objDisk
如果CStr(objDisk(Name))=D:然后
uiDiskSpace = CType(objDisk(" FreeSpace"),System.UInt64)
退出
结束如果
下一个objDisk

''现在我在lFileSize中获得了文件大小的长度
''和uiDiskSpace中的可用磁盘空间为UInt64
''???我如何比较两个???
''------剪断 - 剪切-------

感谢您的帮助,并且有一些很棒的假期呢!
Wolfgang




问候 - OHM #OneHandedMan {at} BTInternet {dot} com


< blockquote>除非你期望查询超过90亿GB的磁盘

的可用空间,只需将uiDiskSpace声明为Long。


" Wolfgang Kaml" < ms@no-spam.kaml.com>在消息中写道

新闻:大江************** @ TK2MSFTNGP10.phx.gbl ...

亲爱的所有人,

我使用以下代码检索某个文件的大小,并使用
磁盘上的可用(空闲)空间。问题是,我得到的文件大小为长整数和可用磁盘空间大小为UInt64。
显然,没有将Long转换为UInt64或<的功能比较两者(我不希望将UInt64转换为Long
,但它应该反过来,对吗?)。

短篇小说:如何将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.ManagementClass(" Win32_LogicalDi sk")
objDisks = objDiskClass.GetInstances()

对于objDisk中的每个objDisk
如果CStr(objDisk(" Name"))=" D:"然后
uiDiskSpace = CType(objDisk(" FreeSpace"),System.UInt64)
退出
结束如果
下一个objDisk

''现在我在lFileSize中获得了文件大小的长度
''和uiDiskSpace中的可用磁盘空间为UInt64
''???我如何比较两个???
''------剪断 - 剪切-------

感谢您的帮助,并且有一些很棒的假期呢!
Wolfgang



好的,所以现在你必须告诉我你是否测试过或者实际上已经完成了/>
,因为我从

uiDiskSpace = CType(objDisk)更改行时收到异常(FreeSpace),System.UInt64)
touiDiskSpace = CType(objDisk(" FreeSpace"),Long)



并将UInt64分配给Long won'也没办法,因为那时候

我得到了一个

类型''System.UInt64''的值不能转换成''Long''。


请告诉我你想要如何完成你提出的解决方案。


谢谢,

Wolfgang


" Stephen Martin" < SM ***** @ removethis.emsoft.andthis.ca>在消息中写道

news:eh ************** @ TK2MSFTNGP12.phx.gbl ...

除非你是期望查询超过90亿千兆字节的可用空间的磁盘,只需将uiDiskSpace声明为Long。

Wolfgang Kaml < ms@no-spam.kaml.com>在消息中写道
新闻:大江************** @ TK2MSFTNGP10.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 the
available (free) space on the disk. The problem is, that I get the size of
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 in the
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 = New System.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

解决方案

Untested . .

Dim ui As UInt64 = Convert.ToUInt64(500)

Dim int64 = Convert.ToInt64(ui)

Regards - OHM

Wolfgang Kaml wrote:

Dear all,

I am using the following code to retrieve the size of a certain file
and the available (free) space on the disk. The problem is, that I
get the size of 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
in the 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 = New
System.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



Regards - OHM# OneHandedMan{at}BTInternet{dot}com


Unless you''re expecting to query a disk with more than 9 billion gigabytes
of free space just declare uiDiskSpace as Long.

"Wolfgang Kaml" <ms@no-spam.kaml.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...

Dear all,

I am using the following code to retrieve the size of a certain file and the available (free) space on the disk. The problem is, that I get the size of
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 in the
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 = New System.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



OK, so now you have to tell me if you tested that or actually have done
that, because I''m getting an Exception when changing the line from

uiDiskSpace = CType(objDisk("FreeSpace"), System.UInt64) touiDiskSpace = CType(objDisk("FreeSpace"), Long)


And assigning the UInt64 to a Long won''t work either, because at that point
I 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 message
news:eh**************@TK2MSFTNGP12.phx.gbl...

Unless you''re expecting to query a disk with more than 9 billion gigabytes
of free space just declare uiDiskSpace as Long.

"Wolfgang Kaml" <ms@no-spam.kaml.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...

Dear all,

I am using the following code to retrieve the size of a certain file and


the

available (free) space on the disk. The problem is, that I get the size


of 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 in the 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 = New System.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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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