Click here to Skip to main content
15,906,081 members
Home / Discussions / C#
   

C#

 
GeneralRe: create and use .DLL Pin
Richard MacCutchan19-Jan-14 22:36
mveRichard MacCutchan19-Jan-14 22:36 
AnswerRe: create and use .DLL Pin
Ron Beyer19-Jan-14 10:38
professionalRon Beyer19-Jan-14 10:38 
GeneralRe: create and use .DLL Pin
BillWoodruff19-Jan-14 12:58
professionalBillWoodruff19-Jan-14 12:58 
GeneralRe: create and use .DLL Pin
Ron Beyer19-Jan-14 13:18
professionalRon Beyer19-Jan-14 13:18 
GeneralRe: create and use .DLL Pin
BillWoodruff19-Jan-14 15:09
professionalBillWoodruff19-Jan-14 15:09 
GeneralRe: create and use .DLL Pin
Ron Beyer19-Jan-14 15:12
professionalRon Beyer19-Jan-14 15:12 
AnswerRe: create and use .DLL Pin
BillWoodruff19-Jan-14 11:00
professionalBillWoodruff19-Jan-14 11:00 
AnswerRe: create and use .DLL Pin
Mycroft Holmes19-Jan-14 18:07
professionalMycroft Holmes19-Jan-14 18:07 
GeneralRe: create and use .DLL Pin
DrooBo19-Jan-14 22:42
DrooBo19-Jan-14 22:42 
Questionabout suppoted technologies Pin
gupta vipin11118-Jan-14 6:25
gupta vipin11118-Jan-14 6:25 
AnswerRe: about suppoted technologies Pin
Dave Kreskowiak18-Jan-14 6:37
mveDave Kreskowiak18-Jan-14 6:37 
SuggestionDelete an edited answer Pin
agent_kruger18-Jan-14 2:28
professionalagent_kruger18-Jan-14 2:28 
GeneralRe: Delete an edited answer Pin
Richard MacCutchan18-Jan-14 4:15
mveRichard MacCutchan18-Jan-14 4:15 
GeneralRe: Delete an edited answer Pin
thatraja18-Jan-14 4:21
professionalthatraja18-Jan-14 4:21 
GeneralRe: Delete an edited answer Pin
agent_kruger18-Jan-14 18:18
professionalagent_kruger18-Jan-14 18:18 
QuestionLINQ Query Grouping Pin
eddieangel17-Jan-14 13:20
eddieangel17-Jan-14 13:20 
AnswerRe: LINQ Query Grouping Pin
OriginalGriff17-Jan-14 20:23
mveOriginalGriff17-Jan-14 20:23 
GeneralRe: LINQ Query Grouping Pin
eddieangel20-Jan-14 6:23
eddieangel20-Jan-14 6:23 
QuestionC# tamir sharp ssh, scp incomplete file transfer Pin
Michael Gaida16-Jan-14 6:03
Michael Gaida16-Jan-14 6:03 
AnswerRe: C# tamir sharp ssh, scp incomplete file transfer Pin
Eddy Vluggen18-Jan-14 0:58
professionalEddy Vluggen18-Jan-14 0:58 
GeneralRe: C# tamir sharp ssh, scp incomplete file transfer Pin
Michael Gaida27-Jan-14 2:23
Michael Gaida27-Jan-14 2:23 
QuestionProblem with shuffling array elements and displaying them Pin
Member 1052812316-Jan-14 2:36
Member 1052812316-Jan-14 2:36 
I have tried to write a program that takes in an array size, fills an array with random elements with each element being used only once. Elements must also be greater than 1 but below the array size. However, when I set the array size as 5, the console only shows me 4 elements!

This happens with all sizes entered, it always shows me 1 element too few! The shuffling is working correctly, however. Can anyone tell me how I can get it to display as many elements as the array size is set to?

Example, if the user enters 5 as the array size, the console should enter 5 random numbers (2,3,5,6,1), but instead enters 4(5,1,2,3)




C#
private void RunQuestionTwo()
{
        int arraySize;                                          //declare variables
        int[] a;


        Console.WriteLine("\nTask 2 \nPlease enter an integer to determine the size of the random array\n");      //ask user to input an integer for the size of the array
        arraySize = Convert.ToInt16(Console.ReadLine());        //read in user's input

        a = new int[arraySize];

        Console.WriteLine("\nThe array will now be displayed\n");

        for (int i = 0; i < a.Length; i++)                      //use a for loop to fill in the array
        {

            a[i] = i + 1;
        }

        Shuffle(a);
}

public void Shuffle(int[] a)
{
    Random rndNumber = new Random();
    int n = a.Length();
    while (n > 1)
    {
        n--;
        int i = rndNumber.Next(1, n);
        int temp = a[i];
        a[i] = a[n];
        a[n] = temp;

        Console.WriteLine(a[n]);
    }

}

AnswerRe: Problem with shuffling array elements and displaying them Pin
Eddy Vluggen16-Jan-14 3:03
professionalEddy Vluggen16-Jan-14 3:03 
GeneralRe: Problem with shuffling array elements and displaying them Pin
Member 1052812317-Jan-14 3:53
Member 1052812317-Jan-14 3:53 
AnswerRe: Problem with shuffling array elements and displaying them Pin
BillWoodruff16-Jan-14 4:03
professionalBillWoodruff16-Jan-14 4:03 

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.