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 生日广州男生祝福语简短