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 红包祝福语简短10字
18 周六早晨祝福语简短