Solved

C# pass a button to a method, then treat that button as an array....

Posted on 2016-10-12
2
46 Views
Last Modified: 2016-10-12
I have an array of buttons
        private Button[] Level = new Button[10];

if i pass Level[5] to a method.   How can I, in that method, access Level[4] or Level[6].  In C I can treat it like a pointer and get to any members..

thanks!
0
Comment
Question by:roujesky
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41841031
Short answer, you can't. Single elements of arrays have no knowledge of their container. What you can do is modify your function to accept 2 arguments. The first argument would be the array containing the buttons and the second argument would be the index of the item you wish to focus on.

I have, in the past, added custom collections and subclassed controls so they can reference their containers but that's a bit of effort to implement well for very little return. I'd just go with the 2 argument approach if I were you.
0
 

Author Closing Comment

by:roujesky
ID: 41841035
thanks!  I know C# is designed to not use pointers.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c# DateTime Format validation 4 69
C# XML Get Values 4 35
Connect Gridview column to Textbox in C# 2 41
ASP.NET data base connection 35 40
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question