简体   繁体   English

如何在vb.net中使用此查询-我无法理解从c#转换为vb.net

[英]How do I use this query in vb.net - I cannot get my head around converting from c# to vb.net

ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery");

foreach (ManagementObject o in new ManagementObjectSearcher(query).Get())
{
    uint level = (uint)o.Properties["EstimatedChargeRemaining"].Value;
} 

Simple in c# - really cannot get my head around it in vb.net -> tried online and manual conversion and keep getting stuck 在C#中简单-真的无法在vb.net中解决它->尝试在线和手动转换并不断陷入困境

For Each o As ManagementObject In New ManagementObjectSearcher(query2) <- getting stuck at this point I think -> not sure how to do the .get For Each o As ManagementObject In New ManagementObjectSearcher(query2) <-我认为此时卡住->不确定如何执行.get

If anyone can help me convert that would be wonderful - preferably the full conversion as I have found parts of my answer all over and they all seem to 'miss a step' 如果有人可以帮助我进行转换,那将是很棒的事情-最好是完全转换,因为我已经找到了答案的一部分,而且他们似乎都“走了一步”

Pretty much exactly as you'd expect: 几乎完全符合您的期望:

Dim query As New ObjectQuery("Select * FROM Win32_Battery")

For Each o As ManagementObject In New ManagementObjectSearcher(query).Get()
    Dim level = CUInt(o.Properties("EstimatedChargeRemaining").Value)
Next

Have you tried developerFusion site to covert your code. 您是否尝试过developerFusion网站来隐藏您的代码。 The following code has converted from developer fusion. 以下代码已从开发人员融合中转换而来。

Dim query As New ObjectQuery("Select * FROM Win32_Battery")

For Each o As ManagementObject In New ManagementObjectSearcher(query).[Get]()
    Dim level As UInteger = CUInt(o.Properties("EstimatedChargeRemaining").Value)
Next

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

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