Windows Powershell创建对象
通过New-Object创建新对象
如果使用构造函数创建一个指定类型的实例对象,该类型必须至少包含一个签名相匹配的构造函数。例如可以通过字符和数字创建一个包含指定个数字符的字符串:
PSC:Powershell>New-ObjectString(‘*',100)
*******************************************************************************
*********************
为什么支持上面的方法,原因是String类中包含一个Void.ctor(Char,Int32)构造函数
PSC:Powershell>[String].GetConstructors()|foreach{$_.tostring()}
Void.ctor(Char*)
Void.ctor(Char*,Int32,Int32)
Void.ctor(SByte*)
Void.ctor(SByte*,Int32,Int32)
Void.ctor(SByte*,Int32,Int32,System.Text.Encoding)
Void.ctor(Char[],Int32,Int32)
Void.ctor(Char[])
Void.ctor(Char,Int32)
通过类型转换创建对象
通过类型转换可以替代New-Object
PSC:Powershell>$date="1999-9-110:23:44" PSC:Powershell>$date.GetType().fullName System.String PSC:Powershell>$date 1999-9-110:23:44 PSC:Powershell>[DateTime]$date="1999-9-110:23:44" PSC:Powershell>$date.GetType().FullName System.DateTime PSC:Powershell>$date
1999年9月1日10:23:44
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短