Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need C# Array help

    Hey

    I need to make an array in C#, where I can put in 10 random numbers, and get them back but sorted from smallest to biggest.

    What I have so far is:

    using System;

    namespace classtest1
    {
    class Program
    {
    static void selectionSort(int arr, int size)
    {
    int[] A = new int[10];
    int i = 0;
    int pass;
    Console.WriteLine("Enter ten intergers and press enter after each:");
    for (pass = 0; pass < size - 1; pass++)
    A[i] = Int32.Parse(Console.ReadLine());

    Console.WriteLine("Here are the sorted intergers");
    for (pass = 0; pass < size - 1; pass++)

    Console.WriteLine("{0}", A[i]);
    Console.ReadLine();

    }
    static void Main()
    {

    return Array.sort;

    }
    }
    }
    If anyone can help out, I'd appreciate it!

    Thanks.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    What do you need help with, specifically?
    For homework help, you need to be very specific; the forum rules are strict about homework help.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just need to know what I am doing wrong.

    The error I get says "error CS0117; 'System.Array' does not contain a definition for 'sort'

    I think I might have a good idea going but I probably have errors in it so it wont sort properly. I just want to be able to inpu 10 random numbers, and get them back sorted from smallest to largest.

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Let me get this straight: You write a function called selectionSort and instead of utilizing it or adding it as a function to the built in Array class, you just call the ambiguous Array.sort?
    1. The error is occuring because returning Array.sort from the main function doesn't make any sense, because the function is void. A void function does not return a value. Judging by your error, Array may not even have a sort function anyhow.
    2. Why is there an "arr" parameter in your selectionsort function if it's never utilized?
    3. Why don't you ever call selectionSort?

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Quote Originally Posted by DecenyDefied View Post
    I just need to know what I am doing wrong.

    The error I get says "error CS0117; 'System.Array' does not contain a definition for 'sort'

    I think I might have a good idea going but I probably have errors in it so it wont sort properly. I just want to be able to inpu 10 random numbers, and get them back sorted from smallest to largest.
    Well, there's a lot wrong, really.
    You're calling the method totally wrong.
    PHP Code:
    static void Main()
    {

    return Array.
    sort;


    That makes no sense, and I'm surprised it even compiles, if it does.
    Your method name is selectionSort. You need to call Program.selectionSort() (you declared it static), but it appears to take arguments, so you'd need to pass those as well.

    I'm not totally sure what the arguments are FOR, though. If you pass something called size, I'd imagine you meant to set an array size dynamically and use it in that loop like you do. But you hard-coded it to 10 and at the moment size is undefined because you aren't passing the value.

    There's more wrong here than right, honestly. You may want to re-read your class material and ask for help from your instructor.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •