Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
AnswerRe: Substitution of Paths in HyperLinkField with File Names Pin
Pete O'Hanlon12-Sep-12 4:55
subeditorPete O'Hanlon12-Sep-12 4:55 
GeneralRe: Substitution of Paths in HyperLinkField with File Names Pin
ASPnoob12-Sep-12 9:59
ASPnoob12-Sep-12 9:59 
QuestionRetrieve name of Printer using SendMessage Pin
toBeH_S11-Sep-12 22:10
toBeH_S11-Sep-12 22:10 
AnswerRe: Retrieve name of Printer using SendMessage Pin
Rage12-Sep-12 6:40
professionalRage12-Sep-12 6:40 
GeneralRe: Retrieve name of Printer using SendMessage Pin
toBeH_S12-Sep-12 8:33
toBeH_S12-Sep-12 8:33 
GeneralRe: Retrieve name of Printer using SendMessage Pin
Rage12-Sep-12 21:25
professionalRage12-Sep-12 21:25 
GeneralRe: Retrieve name of Printer using SendMessage Pin
toBeH_S16-Sep-12 15:18
toBeH_S16-Sep-12 15:18 
QuestionRandom Permutation Interface Pin
Skippums11-Sep-12 15:58
Skippums11-Sep-12 15:58 
I would like to create an extension method that randomly permutes the contents of an ordered list (preferably in-place). This is what I have so far:

C#
public static class PermuteExtensions {

    public void Permute<T, U>(this T list) where T : IEnumerable<U> {
        // Create a copy of the input array
        U[] tempArray = list.ToArray();
        long arraySize = tempArray.LongLength;

        // Create a permutation of indexes, so list[j] = tempArray[indexes[j]]
        long[] indexes = new long[arraySize];
        // ...

        // Assign the new values to the existing ordered collection
        long j = 0;
        IEnumerator<U> enumer = list.GetEnumerator();
        while (enumer.GetNext()) {
            // Uh-oh, cannot assign to enumer.Current!
            enumer.Current = tempArray[indexes[j++]];
        }
    }

}
There are two problems with this approach:
1. I cannot figure out how to modify the contents of an IEnumerable object.
2. How to specify the constraint on T such that I allow this method to be called on the ordered collections (IList, Stack, Queue, List, LinkedList), but not on the unordered collections (IDictionary, Dictionary, ISet, Set).

It is NOT a firm requirement that this be an in-place algorithm. However, I don't know how to construct a new T object that offers a consistent way to add objects for all of the ordered collections listed above. Thanks,
Sounds like somebody's got a case of the Mondays

-Jeff

AnswerRe: Random Permutation Interface Pin
Dave Kreskowiak11-Sep-12 17:44
mveDave Kreskowiak11-Sep-12 17:44 
AnswerRe: Random Permutation Interface Pin
BillWoodruff12-Sep-12 0:05
professionalBillWoodruff12-Sep-12 0:05 
AnswerRe: Random Permutation Interface Pin
Pete O'Hanlon12-Sep-12 0:18
subeditorPete O'Hanlon12-Sep-12 0:18 
GeneralRe: Random Permutation Interface Pin
Dave Kreskowiak12-Sep-12 2:21
mveDave Kreskowiak12-Sep-12 2:21 
AnswerRe: Random Permutation Interface Pin
BobJanova12-Sep-12 1:17
BobJanova12-Sep-12 1:17 
GeneralRe: Random Permutation Interface Pin
Pete O'Hanlon12-Sep-12 1:27
subeditorPete O'Hanlon12-Sep-12 1:27 
GeneralRe: Random Permutation Interface Pin
Skippums12-Sep-12 6:41
Skippums12-Sep-12 6:41 
AnswerRe: Random Permutation Interface Pin
PIEBALDconsult12-Sep-12 3:07
mvePIEBALDconsult12-Sep-12 3:07 
AnswerRe: Random Permutation Interface Pin
Skippums12-Sep-12 7:32
Skippums12-Sep-12 7:32 
GeneralRe: Random Permutation Interface Pin
BillWoodruff13-Sep-12 2:37
professionalBillWoodruff13-Sep-12 2:37 
GeneralRe: Random Permutation Interface Pin
PIEBALDconsult13-Sep-12 3:23
mvePIEBALDconsult13-Sep-12 3:23 
GeneralRe: Random Permutation Interface Pin
PIEBALDconsult13-Sep-12 3:27
mvePIEBALDconsult13-Sep-12 3:27 
GeneralRe: Random Permutation Interface Pin
Skippums13-Sep-12 7:27
Skippums13-Sep-12 7:27 
Questionconvert xdocument to integer Pin
rachel_m11-Sep-12 12:16
rachel_m11-Sep-12 12:16 
AnswerRe: convert xdocument to integer Pin
Pete O'Hanlon11-Sep-12 12:22
subeditorPete O'Hanlon11-Sep-12 12:22 
GeneralRe: convert xdocument to integer Pin
rachel_m11-Sep-12 16:04
rachel_m11-Sep-12 16:04 
GeneralRe: convert xdocument to integer Pin
Eddy Vluggen11-Sep-12 20:55
professionalEddy Vluggen11-Sep-12 20:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.