Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:30:44+00:00 2026-06-04T17:30:44+00:00

Hello Everyone What I am trying to do is call the FillDeck method to

  • 0

Hello Everyone

What I am trying to do is call the “FillDeck” method to fill the “deck []” with 52 array elements. The for loop is used to add the elements – for testing purposes it is just adding the y+x values from the for loop.
What I did was use the variable “placement” to indicate my index position then increment the placement variable so for each loop iteration the index is increased thus adding an array element to that particular index. However, I get the IndexOutOfRangeException which is what I trying to figure out.

To note: I CANNOT automatically use predetermined values for the array, I must call a method which purpose is to add the values to the array. Since it is a card deck having a nested for loop to determine the rank / suit would be a good way to approach this.

Thanks =)

    static void Main(string[] args)
    {
        int [] deck = {};
        FillDeck(deck); // Error Here
    }
    public static void FillDeck(int[] deck)
    {
        int placement = 0;
        // 0 = Ace , 12 = King : 0 = Hearts, 1 = Diamonds, 2 = Clubs, 3 = Spades
        for (int x = 0; x < 13; x++)
            for (int y = 0; x < 4; ++y)
            {
                deck[placement] = x + y;// Error here
                ++placement;
            }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:30:47+00:00Added an answer on June 4, 2026 at 5:30 pm
    int [] deck = {}
    

    This creates an array of size 0.
    You can’t put anything in it.

    You need to write new int[52] (or other appropriate number) to create an array that can actually hold things.

    Alternatively, you can create a List<T>, which can expand to any (reasonable) size by calling the Add() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello everyone I'm trying to work with jboss messaging, does anyone knows the default
Hello everyone I'm trying to improve my Java skills by solving some problems from
Hello everyone I am trying to write a string on image during runtime and
Hello everyone i am trying to implement push notifications with urbanairship i followed the
Hello everyone I've been trying to put some objects in an ASP.NET list box
Hello everyone. I am trying to play a bit with RSA public and private
Hello everyone I have a question... I'm trying to make my sms faker app,
Hello everyone i am trying to format the input number range with php number_format
Hello everyone I been trying get php uploader working but having a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.