473,225 Members | 1,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

sort using powershell assembly?

Hi All,

I'm looking to see if it's feasible to use the SortObjectCommand
included in the Microsoft.Powershell.Commands assembly.

I have a Dictionary

Dictionary<string, int[,]d = new Dictionary<string, int[,]>();

d["apples"] = new int[2,2];
d["peaches"] = new int[2,2];

Assuming we have some data in the value arrays, I would then like to
sort on the keys where d.value[1,1] is higher (for example).

There are of course a number of ways to code the sort, but I'm
interested in using the powershell assembly - I just can't fathom how
to use it in this context.

Any ideas?

cheers,
n

May 22 '07 #1
5 2581
Neil,

Are you using this for another applet you are going to use in
powershell, or as part of your program? If you are going to use it as part
of your program, you are better off using the sorting functionality that is
provided to you by the framework.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Neil Chambers" <n3******@aol.comwrote in message
news:2007052216353875249-n3llyb0y@aolcom...
Hi All,

I'm looking to see if it's feasible to use the SortObjectCommand included
in the Microsoft.Powershell.Commands assembly.

I have a Dictionary

Dictionary<string, int[,]d = new Dictionary<string, int[,]>();

d["apples"] = new int[2,2];
d["peaches"] = new int[2,2];

Assuming we have some data in the value arrays, I would then like to sort
on the keys where d.value[1,1] is higher (for example).

There are of course a number of ways to code the sort, but I'm interested
in using the powershell assembly - I just can't fathom how to use it in
this context.

Any ideas?

cheers,
n

May 22 '07 #2
On 2007-05-22 16:53:21 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comsaid:
Neil,

Are you using this for another applet you are going to use in
powershell, or as part of your program? If you are going to use it as
part of your program, you are better off using the sorting
functionality that is provided to you by the framework.
It's for a program. I am trying to learn C#, in part by converting some
powershell scripts I have. I couldn't find any reference to sorting
within the framework so thought I'd have to write my own algorithm or
use the powershell assembly.

If you can point me to some documentation that would be great!

Cheers,
n

May 22 '07 #3
Neil,

In this case, I really wouldn't use a dictionary for storing the values.
Rather, I would have a structure like this (change the names appropriately):

public struct FruitInfo
{
public string Fruit;
public int[,] Values;
}

Then, you would have instances of your structures that you create in an
array.

Once you have all of these, you can call the static Sort method on the
Array class, passing a delegate to the comparison parameter to determine the
sort order:

// The array of FruitInfo instances.
FruitInfo[] fruitInfo = ...;

// Assume you have populated the array of fruitInfo instances.
Array.Sort(fruitInfo, delegate(FruitInfo x, FruitInfo y) { <code to do
comparison here });
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"n3llyb0y" <n3******@aol.comwrote in message
news:2007052217020350073-n3llyb0y@aolcom...
On 2007-05-22 16:53:21 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comsaid:
>Neil,

Are you using this for another applet you are going to use in
powershell, or as part of your program? If you are going to use it as
part of your program, you are better off using the sorting functionality
that is provided to you by the framework.

It's for a program. I am trying to learn C#, in part by converting some
powershell scripts I have. I couldn't find any reference to sorting within
the framework so thought I'd have to write my own algorithm or use the
powershell assembly.

If you can point me to some documentation that would be great!

Cheers,
n

May 22 '07 #4
On 2007-05-22 17:27:30 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comsaid:
Neil,

In this case, I really wouldn't use a dictionary for storing the
values. Rather, I would have a structure like this (change the names
appropriately):

public struct FruitInfo
{
public string Fruit;
public int[,] Values;
}

Then, you would have instances of your structures that you create
in an array.

Once you have all of these, you can call the static Sort method on
the Array class, passing a delegate to the comparison parameter to
determine the sort order:

// The array of FruitInfo instances.
FruitInfo[] fruitInfo = ...;

// Assume you have populated the array of fruitInfo instances.
Array.Sort(fruitInfo, delegate(FruitInfo x, FruitInfo y) { <code to do
comparison here });
Thanks Nicholas :-)

May 23 '07 #5
On 2007-05-22 17:27:30 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.comsaid:
Neil,

In this case, I really wouldn't use a dictionary for storing the
values. Rather, I would have a structure like this (change the names
appropriately):

public struct FruitInfo
{
public string Fruit;
public int[,] Values;
}

Then, you would have instances of your structures that you create
in an array.

Once you have all of these, you can call the static Sort method on
the Array class, passing a delegate to the comparison parameter to
determine the sort order:

// The array of FruitInfo instances.
FruitInfo[] fruitInfo = ...;

// Assume you have populated the array of fruitInfo instances.
Array.Sort(fruitInfo, delegate(FruitInfo x, FruitInfo y) { <code to do
comparison here });
I'm getting close but I could do with a little more guidance.

Within the comparison code, will I be making use of 'Comparer<myStruct>'?

I can't seem to get a working statement. I need the Comparer to access
an index point within the 'Values' element of the object but I'm
failing. I'm clearly in at the deep end here but a little explanation
of how to get the sort working on the delegates would be much
appreciated.

Cheers,
n

Jun 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ronald S. Cook | last post by:
Currently (manually), I 1) open a Windows SDK Command Prompt and 2) navigate to a particular folder. Then I 3) type a command and press enter. The command is irrelevant (WCF-related) but here it...
3
by: =?Utf-8?B?VGhvbWFzIFcuIEJyb3du?= | last post by:
1. Is there a dedicated discussion group for Windows Powershell? I couldn't find one, but that doesn't necessarily mean there isn't :-) 2. I'm just starting in on learning to use Powershell and...
6
by: Mesan | last post by:
Does anyone have an idea what it takes to administer DB2 through PowerShell? I want to write some scripts to automate my common DB2 management tasks and I'd really like to be able to use...
3
by: Marco Shaw | last post by:
I've got some C# code to create a custom PowerShell cmdlet with these statements: .... using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; .... ...
1
by: Alexander Vasilevsky | last post by:
Hi! How to debug Powershell commandlets? -- http://www.alvas.net - Audio tools for C# and VB.Net developers
3
by: sridhard2406 | last post by:
Hi I didn't find a forum for powershell so i'm my query here itself. I'm runnung a powershell script and i want to redirect the output to a xml after redirecting the output i need to search a...
24
by: =?Utf-8?B?QnJpYW4gTmljaG9sc29u?= | last post by:
Hello, I'm trying to create an admin page that can run miscellaneous scripts for our IT department. Currently, I'm trying to create a script that can map a network drive for a user (e.g. a form...
1
by: =?Utf-8?B?bGVyb3ljYXJs?= | last post by:
Problem is that I want to use PowerShell and a csv file to update a database (Access, SQL, whatever). I do this now with VBScript. I have made a simple example of the ps1 script and text file and...
1
by: SCRIPT KEEPER | last post by:
Hello, I am a complete noob and just starting off with csharp so I apologize for my basic question. I am wanting to start powershell from inside a batch script and then to pass the powershell args...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.