Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - The easiest way to create an empty data structure

Reply
 
Old 08-21-2006   #1 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

The easiest way to create an empty data structure

I have discovered how to create an empty data structure very easily and yet
effectively.

----- 8< -----

# I guess this way is standard and verbose
function MyObject1
{
$e = New-Object PSObject
$e | Add-Member NoteProperty p1 $null
$e | Add-Member NoteProperty p2 $null
$e | Add-Member NoteProperty p3 $null
$e
}

# I guess this way is not standard and brief
function MyObject2
{
1 | Select-Object p1, p2, p3
}

# The results are the same
MyObject1 | gm
MyObject2 | gm

# The brief not standard way looks even more effective
Measure-Command {1..111 | % {MyObject1}}
Measure-Command {1..111 | % {MyObject2}}

----- 8< -----

LOL

--
Thanks,
Roman

My System SpecsSystem Spec
Old 08-22-2006   #2 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

RE: The easiest way to create an empty data structure

Terminology:

I think “a custom object with null properties” is more correct than “an
empty data structure”.

--
Thanks,
Roman

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VB 2005 Windows forms Data Structure .NET General
re-create user folder structure Vista account administration
Extract data out of a seemingly complex structure .NET General
Zip extract is empty directory structure Vista file management
Create a folder structure Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46