Hi All,
I'm looking to see if it's feasible to use the SortObjectComma nd
included in the Microsoft.Power shell.Commands assembly.
I have a Dictionary
Dictionary<stri ng, int[,]d = new Dictionary<stri ng, 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 5 2609
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.co m
"Neil Chambers" <n3******@aol.c omwrote in message
news:2007052216 353875249-n3llyb0y@aolcom ...
Hi All,
I'm looking to see if it's feasible to use the SortObjectComma nd included
in the Microsoft.Power shell.Commands assembly.
I have a Dictionary
Dictionary<stri ng, int[,]d = new Dictionary<stri ng, 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
On 2007-05-22 16:53:21 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omsaid:
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
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(frui tInfo, delegate(FruitI nfo x, FruitInfo y) { <code to do
comparison here });
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"n3llyb0y" <n3******@aol.c omwrote in message
news:2007052217 020350073-n3llyb0y@aolcom ...
On 2007-05-22 16:53:21 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omsaid:
>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
On 2007-05-22 17:27:30 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omsaid:
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(frui tInfo, delegate(FruitI nfo x, FruitInfo y) { <code to do
comparison here });
Thanks Nicholas :-)
On 2007-05-22 17:27:30 +0100, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omsaid:
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(frui tInfo, delegate(FruitI nfo 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<myStr uct>'?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 is FYI:
svcutil http://localhost/COWFeedyardService/Services/Pen.svc /out:Pen.vb
/config:App.config /language:VB
All works fine, but I need to do this over a hundred times changing "Pen" to
the names of the other classes and re-executing.
|
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 doing so by slowly
(very slowly) attempting to port some existing CMD and Perl scripts. I'm
blocked right now on something that should be very simple (I would think)...
I want to use SQLCMD to issue a query and parse/format the return string....
|
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 PowerShell for
that scripting, but I can't find a way to run DB2 comands.
I've tried
db2cmd /w
db2cmd /w /i
db2cmd /i (this one got me the closest)
db2clpex (looked promising but not so helpfu)
|
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;
....
My compile fails using csc.exe:
|
by: Alexander Vasilevsky |
last post by:
Hi!
How to debug Powershell commandlets?
--
http://www.alvas.net - Audio tools for C# and VB.Net developers
| |
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 pattern in the outfile and print on the console.
is the below is correct
filename.ps1 |out-file abc.xml | search-string -pattern "Status"
|
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 where I can input \\path\folder, drive
letter, and domain\user). Is this possible? If so, can someone point me in
the right direction?
Thank you,
Brian Nicholson
|
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 it works BUT only inserts one
row. If the sample "simpleTest.ps1" is run from powershell the extraction is
fine. I have commented out the database stuff which works when a instance of
Access "Adatabase" with a "Table1" with all fields set to...
|
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 from the batch, so from the batch I can use the name of the compiled csharp app without having to include the "call" command.
Something like "Compiled Csharp app.exe" "PowerShell Args" etc.....
Thank You for any help.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |