Solved

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

Posted on 2016-10-12
2
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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