Can anyone explain why the following (using the System
namespace qualifer) works:
Add-Type @"
public class BitValueChecker
{
public static bool IsBitSetZeroBase开发者_如何学God(uint value, uint bitNumber)
{
if (bitNumber < 0 || bitNumber >= 32)
throw new System.Exception("Invalid bit number must be >= 0 and <= 31");
uint checkValue = value & System.Convert.ToUInt32(System.Math.Pow(2, bitNumber));
return checkValue > 0;
}
}
"@
while the below (essentially identical) snippet causes PS to complain that Exception
, Convert
and Math
"do not exist in the current context"?
Add-Type @"
public class BitValueChecker
{
public static bool IsBitSetZeroBased(uint value, uint bitNumber)
{
if (bitNumber < 0 || bitNumber >= 32)
throw new Exception("Invalid bit number must be >= 0 and <= 31");
uint checkValue = value & Convert.ToUInt32(Math.Pow(2, bitNumber));
return checkValue > 0;
}
}
"@
In your second code you have to add
Add-Type @"
using System;
public class BitValueChecker
{
....
Like in a c# code.
精彩评论