Get the App
SLTechnology News&Howtos  ›  Servers  › 

PowerShell calls .net static classes and methods directly

Shulou Source: shulou.com Published: 2022-06-02 20:37:02 10月03日 Update

Not all. NET Framework classes can be created using New-Object. For example, if you try to create a System.Environment or System.Math object using New-Object, you will receive the following error message:

PS> New-Object System.EnvironmentNew-Object : Constructor not found. Cannot find an appropriate constructor fortype System.Environment.At line:1 char:11+ New-Object [System.Math]::Floor(-3.3)-4PS> [System.Math]::Ceiling(3.3)4PS> [System.Math]::Ceiling(-3.3)-3PS> [System.Math]::Max(2,7)7PS> [System.Math]::Min(2,7)2PS> [System.Math]::Truncate(9.3)9PS> [System.Math]::Truncate(-9.3)-9

Use get-member to see the supported arithmetic methods for this static class:

PS> [System.Math] | Get-Member -Static -MemberType Methods TypeName: System.MathName MemberType Definition---- ---------- ----------Abs Method static System.Single Abs(Single value), static Sy... Acos Method static System.Double Acos(Double d)Asin Method static System.Double Asin(Double d)Atan Method static System.Double Atan(Double d)Atan2 Method static System.Double Atan2(Double y, Double x)BigMul Method static System.Int64 BigMul(Int32 a, Int32 b)Ceiling Method static System.Double Ceiling(Double a), static Sy... Cos Method static System.Double Cos(Double d)Cosh Method static System.Double Cosh(Double value)DivRem Method static System.Int32 DivRem(Int32 a, Int32 b, Int3... Equals Method static System.Boolean Equals(Object objA, Object ... Exp Method static System.Double Exp(Double d)Floor Method static System.Double Floor(Double d), static Syst... IEEERemainder Method static System.Double IEEERemainder(Double x, Doub... Log Method static System.Double Log(Double d), static System... Log10 Method static System.Double Log10(Double d)Max Method static System.SByte Max(SByte val1, SByte val2), ... Min Method static System.SByte Min(SByte val1, SByte val2), ... Pow Method static System.Double Pow(Double x, Double y)ReferenceEquals Method static System.Boolean ReferenceEquals(Object objA... Round Method static System.Double Round(Double a), static Syst... Sign Method static System.Int32 Sign(SByte value), static Sys... Sin Method static System.Double Sin(Double a)Sinh Method static System.Double Sinh(Double value)Sqrt Method static System.Double Sqrt(Double d)Tan Method static System.Double Tan(Double a)Tanh Method static System.Double Tanh(Double value)Truncate Method static System.Decimal Truncate(Decimal d), static...

You can also follow Weixin Official Accounts below for more content

Tags: Method static object information type process error attempt work operation reason public content property report mathematics way is in more message Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology macOS Shulou Information vpn