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

  • Home
  • SEARCH
  • 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 650775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:05:23+00:00 2026-05-13T22:05:23+00:00

I am trying to place a value (from an object) in a variable and

  • 0

I am trying to place a value (from an object) in a variable and place it in a textbox in a form.

Here is the form code:

public Form1(Deck mainDeck)
    {
        InitializeComponent();
        int Val = mainDeck.ReturnCard(10);
        textBox1.Text = Val.ToString();
    }

mainDeck is an object in my Program.cs file

The problem line is this one: int Val = mainDeck.ReturnCard(10);

Oops, wrong error.
This is the real one:

Error 1 The name 'mainDeck' does not exist in the current context C:\Users\Chris\Documents\Visual Studio 2008\Projects\Pcard\Pcard\Form1.cs 17 23 Pcard

Here is my Program.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Pcard
{
    class Deck
    {
        public Deck()
        {
            // Assign standard deck to new deck object
            //   int j;
            for (int i = 0; i != currentDeck.Length; i++)
            {
                currentDeck[i] = originalCards[i];
            }
            // Fisher-Yates Shuffling Algorithim    ---   Do initial shuffle
            Random rnd = new Random();

            for (int k = currentDeck.Length - 1; k >= 0; k--)
            {
                int r = rnd.Next(0, k + 1);

                int tmp = currentDeck[k];
                currentDeck[k] = currentDeck[r];
                currentDeck[r] = tmp;
            }
        }
        public void Shuffle()
        {
            Random rnd = new Random();

            for (int k = currentDeck.Length - 1; k >= 0; k--)
            {
                int r = rnd.Next(0, k + 1);

                int tmp = currentDeck[k];
                currentDeck[k] = currentDeck[r];
                currentDeck[r] = tmp;
            }
        }
        public int[] ReturnDeck()
        {
            return currentDeck;
        }
        public int ReturnCard(int num)
        {
            return currentDeck[num];
        }

        public int[] originalCards = new int[54]
        {
            0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
            0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
            0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,
            0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
            0x50, 0x51
        };
        private int[] currentDeck = new int[54];

    }
   public class Program
    {
        static void Main(string[] args)
        {
            // Create a Deck object
            Deck mainDeck = new Deck();
            Console.WriteLine("Here is the card array:");
            for (int index = 0; index != 54; index++)
            {
                string card = mainDeck.ReturnCard(index).ToString("x");
                Console.WriteLine("0x" + card);
            }
            //Return 10th Card
            int PickCard = mainDeck.ReturnCard(10);
            Console.WriteLine("Here is the 10th Card");
            Console.WriteLine("0x" + PickCard);
            //Shuffle
            mainDeck.Shuffle();
            Console.WriteLine("Shuffling..");
            PickCard = mainDeck.ReturnCard(10);
            Console.WriteLine("Here is the 10th card now: 0x" + PickCard);
            Application.Run(new Form1(maindeck));
        }
    }
}

Edit: Okay, I am passing mainDeck to the Form, but I am now getting a different error:
Error 1 Inconsistent accessibility: parameter type 'Pcard.Deck' is less accessible than method 'Pcard.Form1.Form1(Pcard.Deck)' C:\Users\Chris\Documents\Visual Studio 2008\Projects\Pcard\Pcard\Form1.cs 14 16 Pcard

Edit: Edit: Alright, I now have this working, but I ran into a related problem, so I would rather put it here than in a new question.

Passing mainDeck to the Form1 works fine, but what about if I want to have a button click call a method in this object. I tried passing mainDeck like this:

 private void button1_Click(object sender, Deck mainDeck, EventArgs e)
        {
            mainDeck.Shuffle();
        }

I get this error:
Error 1 No overload for 'button1_Click' matches delegate 'System.EventHandler' C:\Users\Chris\Documents\Visual Studio 2008\Projects\Pcard\Pcard\Form1.Designer.cs 51 35 Pcard

GRR!

  • 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-05-13T22:05:23+00:00Added an answer on May 13, 2026 at 10:05 pm

    The line
    Deck mainDeck = new Deck();
    just creates a local variable with name mainDeck… Which is accessible only in the Main() Method…

    Place the Declaration above the Main method in the class… Make the program class public and the maindeck as public static… like this

    public class Program 
    { 
           // Create a Deck object 
       public static Deck mainDeck = new Deck(); 
        static void Main(string[] args) 
       { 
         .....
    
       }
    

    Then you can access from your Form as

     int Val = Program.mainDeck.ReturnCard(10);
    

    Hope this helps.

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

Sidebar

Ask A Question

Stats

  • Questions 405k
  • Answers 405k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What's in the documentation: In your view controller, override shouldAutorotateToInterfaceOrientation:… May 15, 2026 at 5:41 am
  • Editorial Team
    Editorial Team added an answer And I have the following XSL: <xsl:template match="/"> <xsl:copy-of select="ancestor::criterion/>… May 15, 2026 at 5:41 am
  • Editorial Team
    Editorial Team added an answer FM is giving you good advice. mk_accessors needs to run… May 15, 2026 at 5:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.