Click here to Skip to main content
15,121,818 members
Home / Discussions / C#
   

C#

 
AnswerRe: Substitution of Paths in HyperLinkField with File Names Pin
Pete O'Hanlon12-Sep-12 5:55
mvePete O'Hanlon12-Sep-12 5:55 
GeneralRe: Substitution of Paths in HyperLinkField with File Names Pin
ASPnoob12-Sep-12 10:59
MemberASPnoob12-Sep-12 10:59 
QuestionRetrieve name of Printer using SendMessage Pin
toBeH_S11-Sep-12 23:10
MembertoBeH_S11-Sep-12 23:10 
AnswerRe: Retrieve name of Printer using SendMessage Pin
Rage12-Sep-12 7:40
professionalRage12-Sep-12 7:40 
GeneralRe: Retrieve name of Printer using SendMessage Pin
toBeH_S12-Sep-12 9:33
MembertoBeH_S12-Sep-12 9:33 
GeneralRe: Retrieve name of Printer using SendMessage Pin
Rage12-Sep-12 22:25
professionalRage12-Sep-12 22:25 
GeneralRe: Retrieve name of Printer using SendMessage Pin
toBeH_S16-Sep-12 16:18
MembertoBeH_S16-Sep-12 16:18 
QuestionRandom Permutation Interface Pin
Skippums11-Sep-12 16:58
MemberSkippums11-Sep-12 16: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 18:44
mveDave Kreskowiak11-Sep-12 18:44 
AnswerRe: Random Permutation Interface Pin
BillWoodruff12-Sep-12 1:05
mveBillWoodruff12-Sep-12 1:05 
AnswerRe: Random Permutation Interface Pin
Pete O'Hanlon12-Sep-12 1:18
mvePete O'Hanlon12-Sep-12 1:18 
GeneralRe: Random Permutation Interface Pin
Dave Kreskowiak12-Sep-12 3:21
mveDave Kreskowiak12-Sep-12 3:21 
AnswerRe: Random Permutation Interface Pin
BobJanova12-Sep-12 2:17
MemberBobJanova12-Sep-12 2:17 
GeneralRe: Random Permutation Interface Pin
Pete O'Hanlon12-Sep-12 2:27
mvePete O'Hanlon12-Sep-12 2:27 
GeneralRe: Random Permutation Interface Pin
Skippums12-Sep-12 7:41
MemberSkippums12-Sep-12 7:41 
AnswerRe: Random Permutation Interface Pin
PIEBALDconsult12-Sep-12 4:07
professionalPIEBALDconsult12-Sep-12 4:07 
AnswerRe: Random Permutation Interface Pin
Skippums12-Sep-12 8:32
MemberSkippums12-Sep-12 8:32 
GeneralRe: Random Permutation Interface Pin
BillWoodruff13-Sep-12 3:37
mveBillWoodruff13-Sep-12 3:37 
GeneralRe: Random Permutation Interface Pin
PIEBALDconsult13-Sep-12 4:23
professionalPIEBALDconsult13-Sep-12 4:23 
GeneralRe: Random Permutation Interface Pin
PIEBALDconsult13-Sep-12 4:27
professionalPIEBALDconsult13-Sep-12 4:27 
GeneralRe: Random Permutation Interface Pin
Skippums13-Sep-12 8:27
MemberSkippums13-Sep-12 8:27 
Questionconvert xdocument to integer Pin
rachel_m11-Sep-12 13:16
Memberrachel_m11-Sep-12 13:16 
AnswerRe: convert xdocument to integer Pin
Pete O'Hanlon11-Sep-12 13:22
mvePete O'Hanlon11-Sep-12 13:22 
GeneralRe: convert xdocument to integer Pin
rachel_m11-Sep-12 17:04
Memberrachel_m11-Sep-12 17:04 
GeneralRe: convert xdocument to integer Pin
Eddy Vluggen11-Sep-12 21:55
professionalEddy Vluggen11-Sep-12 21: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.